Skip to content

Add Error Messages & Improve Error Handling#88

Open
Lightning11wins wants to merge 4 commits intomasterfrom
improve-error-handling
Open

Add Error Messages & Improve Error Handling#88
Lightning11wins wants to merge 4 commits intomasterfrom
improve-error-handling

Conversation

@Lightning11wins
Copy link
Contributor

Changes extracted from #85.
Should not affect business logic, other than improving error case handling. Review should be easy.

@Lightning11wins Lightning11wins self-assigned this Mar 4, 2026
@Lightning11wins Lightning11wins added enhancement ai-review Request AI review of this PR labels Mar 4, 2026
@greptile-apps
Copy link

greptile-apps bot commented Mar 4, 2026

Greptile Summary

This PR improves error handling in centrallix-lib/src/cxsec.c by replacing bare return -1 statements in cxsecVerifySymbol and cxsecVerifySymbol_n with goto err jumps that emit a fprintf(stderr, ...) warning before returning. It also correctly preserves the original sym pointer and length (original_n) before the loop mutates them, so the error message always displays the full invalid symbol rather than a truncated suffix.

Key changes and observations:

  • The core fix (saving original_symbol/original_n before mutation) is correct and resolves the stale-pointer issue in cxsecVerifySymbol_n.
  • %.*s with (int)original_n is used correctly in cxsecVerifySymbol_n to bound output for non-null-terminated strings; %s with the null-terminated cxsecVerifySymbol is also correct.
  • Convention violation: Both functions use the error label err: instead of error:, which violates the project's goto error convention — this should be renamed.
  • Indentation inconsistency: Newly added variable declarations use 4-space indentation while the rest of each function uses hard tabs, creating inconsistency.

Confidence Score: 3/5

  • Safe to merge after minor cleanup: label naming and indentation style violations should be fixed first.
  • The functional logic improvements (saving original pointer/length, using %.*s for bounded output) are correct and address previously identified issues. The only remaining problems are style convention violations: goto err should be goto error per the project style guide, and new variable declarations use spaces instead of tabs. Neither issue affects runtime behavior, but both should be corrected for consistency.
  • centrallix-lib/src/cxsec.c — label naming and indentation style in both new error-handling blocks

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A["cxsecVerifySymbol(sym)"] --> B["Save original_symbol = sym"]
    B --> C{"First char valid?\n(alpha or underscore)"}
    C -- No --> ERR1["goto err"]
    C -- Yes --> D["sym++"]
    D --> E{"while *sym != NUL"}
    E -- "char invalid" --> ERR1
    E -- "char valid" --> F["sym++"]
    F --> E
    E -- "end of string" --> G["return 0 ✓"]
    ERR1 --> H["fprintf(stderr, WARNING: '%s'..., original_symbol)\nreturn -1"]

    A2["cxsecVerifySymbol_n(sym, n)"] --> B2["Save original_symbol = sym\nSave original_n = n"]
    B2 --> C2{"n <= 0 OR\nfirst char invalid?"}
    C2 -- Yes --> ERR2["goto err"]
    C2 -- No --> D2["n--; sym++"]
    D2 --> E2{"while n > 0"}
    E2 -- "char invalid" --> ERR2
    E2 -- "char valid" --> F2["sym++; n--"]
    F2 --> E2
    E2 -- "n exhausted" --> G2["return 0 ✓"]
    ERR2 --> H2["fprintf(stderr, WARNING: '%.*s'..., original_n, original_symbol)\nreturn -1"]
Loading

Last reviewed commit: c1fef33

@Lightning11wins
Copy link
Contributor Author

@greptileai Please re-review this PR and let me know if you have any other comments, or let me know if the PR is ready to merge.

@Lightning11wins
Copy link
Contributor Author

@greptileai I fixed your previous issues and also made more changes. Double check that the previous issues are fixed and scan the new changes to ensure that they don't have any issues.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ai-review Request AI review of this PR enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant