Skip to content

Add mjb_status_message function - #55

Merged
zaerl merged 2 commits into
mainfrom
add/status-message-function
Jul 28, 2026
Merged

Add mjb_status_message function#55
zaerl merged 2 commits into
mainfrom
add/status-message-function

Conversation

@zaerl

@zaerl zaerl commented Jul 28, 2026

Copy link
Copy Markdown
Owner

No description provided.

Signed-off-by: Francesco Bigiarini <francesco.bigiarini@gmail.com>
@zaerl
zaerl requested a review from Copilot July 28, 2026 21:47
@zaerl zaerl self-assigned this Jul 28, 2026

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds a new public utility API (mjb_status_message) that maps mjb_status codes to static English messages, and wires it through the generator/docs, WASM/TypeScript bindings, tests, fuzzing, and the CLI’s JSON error output so shell commands can report errors more consistently.

Changes:

  • Introduce mjb_status_message(mjb_status) in the core C library, export it to WASM, and document it in API.md.
  • Update the CLI to emit structured JSON errors (and refactor shell printing helpers) while switching many command error paths to use mjb_status_message.
  • Add new tests/examples and extend fuzz coverage for the new API.

Reviewed changes

Copilot reviewed 23 out of 24 changed files in this pull request and generated 8 comments.

Show a summary per file
File Description
utils/generate/types.ts Adds a statuses enum-value list for generator/UI purposes.
utils/generate/html-function.ts Uses statuses to render mjb_status args as a select input in generated HTML.
utils/generate/functions.ts Registers the new mjb_status_message public API for header/doc/WASM generation.
tests/shell/break-json.cmake Updates expected JSON error output behavior for break with no input.
tests/mojibake.c Adds unit assertions for mjb_status_message known/unknown cases.
tests/example.c Adds generated example/coverage snippet for mjb_status_message.
src/shell/shell.h Declares new mjbsh_error() helper for consistent CLI error reporting.
src/shell/shell.c Implements mjbsh_error() and refactors varargs printing to safely reuse va_list.
src/shell/commands/string.c Switches case-mapping command to use mjbsh_error() + mjb_status_message().
src/shell/commands/normalize.c Switches normalization commands to use mjbsh_error() + status messages.
src/shell/commands/locale.c Switches locale parsing command to use mjbsh_error() + status messages.
src/shell/commands/filter.c Switches filter command failures to use mjbsh_error() + status messages.
src/shell/commands/emoji.c Switches codepoint-input failure to use mjbsh_error().
src/shell/commands/codepoint.c Adds CLI error messages for invalid/failed codepoint parsing/encoding.
src/shell/commands/character.c Switches character iteration failure to use mjbsh_error() + status messages.
src/shell/commands/break.c Switches JSON “missing input” and “unknown mode” errors to mjbsh_error().
src/shell/commands/bidi.c Switches bidi resolve failure to use mjbsh_error() + status messages.
src/mojibake.h Exposes the new public declaration mjb_status_message.
src/mojibake.c Implements the status-to-message mapping table.
src/CMakeLists.txt Exports _mjb_status_message for the Emscripten/WASM build.
src/api/mojibake.d.ts Adds TypeScript WASM module typing for _mjb_status_message.
src/api/index.ts Adds Mojibake.statusMessage() wrapper around the WASM export.
fuzz/fuzz.c Adds a fuzz case to exercise mjb_status_message across many inputs.
API.md Adds generated API documentation for mjb_status_message.
Comments suppressed due to low confidence (1)

src/shell/commands/normalize.c:81

  • Avoid using the status message as a printf-style format string here as well; pass it via "%s" to prevent format-string interpretation.
    if(status != MJB_STATUS_OK) {
        free(codepoints);

        return mjbsh_error(mjb_status_message(status));
    }

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/shell/commands/string.c
Comment thread src/shell/commands/normalize.c
Comment thread src/shell/commands/locale.c
Comment on lines 18 to 20
if(status != MJB_STATUS_OK) {
fprintf(stderr, "Could not filter string\n");

return 1;
return mjbsh_error(mjb_status_message(status));
}
Comment thread src/shell/commands/character.c
Comment thread src/shell/commands/bidi.c
Comment on lines 376 to 378
if(!mjbsh_break_parse_mode(argv[0], &mode)) {
fprintf(stderr, "break: unknown mode: %s\n", argv[0]);
fprintf(stderr, "break: expected all, grapheme, word, line, or sentence\n");

return 1;
return mjbsh_error("break: unknown mode");
}
Comment thread src/mojibake.c Outdated
Comment on lines +144 to +146
if(status >= MJB_STATUS_OK && status <= MJB_STATUS_FEATURE_NOT_ENABLED) {
message = messages[status];
}
Signed-off-by: Francesco Bigiarini <francesco.bigiarini@gmail.com>
@zaerl
zaerl merged commit c2fc9f2 into main Jul 28, 2026
31 checks passed
@zaerl
zaerl deleted the add/status-message-function branch July 28, 2026 22:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants