Add mjb_status_message function - #55
Merged
Merged
Conversation
Signed-off-by: Francesco Bigiarini <francesco.bigiarini@gmail.com>
Contributor
There was a problem hiding this comment.
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 inAPI.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 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 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 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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.