Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[pull] master from erlang:master #225

Merged
merged 3 commits into from
Feb 21, 2025
Merged

[pull] master from erlang:master #225

merged 3 commits into from
Feb 21, 2025

Conversation

pull[bot]
Copy link

@pull pull bot commented Feb 21, 2025

See Commits and Changes for more details.


Created by pull[bot] (v2.0.0-alpha.1)

Can you help keep this open source service alive? 💖 Please sponsor : )

Summary by Sourcery

This pull request enhances the xmerl library by adding comprehensive error handling using try-catch blocks to prevent crashes and improve debugging information. It also addresses potential infinite loops caused by cyclic definitions in XML schemas.

Bug Fixes:

  • Fixes several potential crash scenarios by adding try-catch blocks to handle exceptions that were previously uncaught, improving the robustness of the xmerl library.
  • Fixes potential infinite loops due to cyclic definitions in XML schemas.

Enhancements:

  • Improves error reporting by including stack traces in error messages, providing more detailed information for debugging.
  • Enhances the handling of invalid or malformed data by using try-catch blocks to prevent crashes and provide more informative error messages.

- Rewrote some recursion when calling continuation fun
  in xmerl_sax_parser_base.
- Remove all old style catch calls in xmerl
* lars/xmerl/tail-recursion-bug-27/OTP-19496:
  Fix a tail recursion bug in sax parser
@pull pull bot added the ⤵️ pull label Feb 21, 2025
@pull pull bot merged commit 64185e7 into garazdawi:master Feb 21, 2025
Copy link

sourcery-ai bot commented Feb 21, 2025

Reviewer's Guide by Sourcery

This pull request replaces catch blocks with try...catch blocks throughout the codebase to improve error handling. This change ensures that exceptions are properly caught and handled, preventing unexpected program termination and providing more informative error messages. The changes primarily affect modules related to XML parsing, validation, and schema processing.

Sequence diagram for state2file function

sequenceDiagram
  participant S as xsd_state record
  participant M as xmerl_xsd module
  participant E as ets table

  S->M: state2file(S, FileName)
  M->M: save_xsd_state(S)
  M->E: ets:tab2file(S#xsd_state.table, FileName + ".xss")
  alt ets:tab2file succeeds
    E-->>M: ok
    M-->>S: ok
  else ets:tab2file fails
    E-->>M: {error, Reason, StackTrace}
    M-->>S: {error, {[], ?MODULE, {Reason, StackTrace}}}
  end
Loading

Sequence diagram for validate3 function

sequenceDiagram
  participant M as xmerl_xsd module
  participant S as xsd_state record
  participant V as validate_xml function

  M->V: validate_xml(Xml, S)
  alt validate_xml succeeds
    V-->>M: {XML2, Rest, Sx}
    M->M: lists:dropwhile(...)
    alt lists:dropwhile returns empty list
      M->M: return {Xml, S2}
    else lists:dropwhile returns non-empty list
      M->M: acc_errs(Sx, ...)
      M->M: return {Xml, S2}
    end
  else validate_xml returns error
    V-->>M: {error, Reason}
    M->M: acc_errs(S, Reason)
    M->M: return {Xml, S2}
  else validate_xml throws error:Reason:StackTrace
    V-->>M: error:Reason:StackTrace
    M->M: acc_errs(S, ...)
    M->M: return {Xml, S2}
  else validate_xml throws exit:Reason
    V-->>M: exit:Reason
    M->M: acc_errs(S, ...)
    M->M: return {Xml, S2}
  end
  M->M: save_to_file(S2, ...)
  M->M: return S2#xsd_state.errors
Loading

Updated class diagram for xsd_state

classDiagram
  class xsd_state {
    -table
    -errors
    -schema_name
    -xsd_base
    -num_el
    -scope
    -circularity_disallowed
    -tab2file
    +state2file(FileName)
    +file2state(FileName)
    +validate3(Schema, Xml)
    +process_schema2(State, Schema)
    +optional(Content)
    +occurrence(El, Occ, S)
    +check_any(E, Any, Env, S)
    +check_substitutionGroups(SGs, S)
    +check_cyclic_defs(S)
    +merge_derived_types(Type1, Type2, Mode, S)
    +qualified_name(Name, NS, Default, Scope)
    +delete_table()
    +print_table()
    +save_to_file()
    +save_in_table(Name, ElDef)
    +get_schema_cm(Tab, Namespace)
    +get_schema_cm1(Tab, Namespace)
    +get_no_namespace_content(Tab)
  }
  note for xsd_state "This class represents the state of the XSD validator."
Loading

File-Level Changes

Change Details Files
Improved error handling by adding try-catch blocks to handle exceptions that may occur during ETS operations, XML validation, and other processes.
  • Wrapped ets:tab2file with a try-catch block to handle potential errors during table saving.
  • Wrapped ets:file2tab with a try-catch block to handle potential errors during table loading.
  • Wrapped ets:insert with a try-catch block in save_xsd_state to handle potential errors during table insertion.
  • Wrapped ets:lookup with a try-catch block in load_xsd_state to handle potential errors during table lookup.
  • Wrapped validate_xml with a try-catch block in validate3 to handle potential errors during XML validation.
  • Wrapped sofs:family_to_digraph with a try-catch block in check_substGr_acyclic and check_cyclic_defs to handle potential errors during graph creation.
  • Wrapped merge_derived_types2 with a try-catch block in merge_derived_types to handle potential errors during type merging.
  • Wrapped ets:delete with a try-catch block in delete_table to handle potential errors during table deletion.
  • Wrapped ets:tab2list with a try-catch block in print_table to handle potential errors during table listing.
  • Wrapped ets:tab2list with a try-catch block in save_to_file to handle potential errors during table listing.
  • Wrapped scan_number with a try-catch block in xmerl_xpath_pred to handle potential errors during number scanning.
  • Wrapped ets:match with a try-catch block in check_elements to handle potential errors during table matching.
  • Wrapped scan_entity_ref with a try-catch block in scan_reference to handle potential errors during entity reference scanning.
lib/xmerl/src/xmerl_xsd.erl
lib/xmerl/src/xmerl_xsd_type.erl
lib/xmerl/src/xmerl_xpath_pred.erl
lib/xmerl/src/xmerl_scan.erl
lib/xmerl/src/xmerl_validate.erl
lib/xmerl/src/xmerl_regexp.erl
Modified the optional function to use try-catch blocks instead of catch blocks to handle exceptions.
  • Replaced catch is_optional_content(Content) with try is_optional_content(Content) catch throw:false -> false end in the optional function for #chain, #alternative and {all, {Content, _}} records.
lib/xmerl/src/xmerl_xsd.erl
Refactored the AttVal function to use try-catch blocks instead of catch blocks to handle exceptions.
  • Replaced case catch mk_int_or_atom(V) of with try mk_int_or_atom(V) of in the AttVal function.
lib/xmerl/src/xmerl_xsd.erl
Modified the check_any function to use try-catch blocks instead of catch blocks to handle exceptions.
  • Replaced case catch validate_xml(E,S#xsd_state{scope=[]}) of with try validate_xml(E,S#xsd_state{scope=[]}) of in the check_any function.
lib/xmerl/src/xmerl_xsd.erl
Modified the cmp_substGr_types function to use try-catch blocks instead of catch blocks to handle exceptions.
  • Replaced case catch cmp_substGr_types(Head,SG,S_in) of with try cmp_substGr_types(Head,SG,S_in) of in the cmp_substGr_types function.
lib/xmerl/src/xmerl_xsd.erl
Modified the atom_if_shortasciilist function to use try-catch blocks instead of catch blocks to handle exceptions.
  • Replaced case catch list_to_atom(N) of with try list_to_atom(N) of in the atom_if_shortasciilist function.
lib/xmerl/src/xmerl_xsd.erl
Modified the check_simpleType function to use try-catch blocks instead of catch blocks to handle exceptions.
  • Replaced `-define(catch_exit(Call,Value,ErrorCause),
case catch (_Call_) of` with `-define(catch_exit(_Call_,_Value_,_ErrorCause_),
try (_Call_) of` in the `check_simpleType` function.</li></ul> | `lib/xmerl/src/xmerl_xsd_type.erl` |

| Modified the check_anyURI function to use try-catch blocks instead of catch blocks to handle exceptions. |

  • Replaced case catch file:read_file_info(filename:join(S#xsd_state.xsd_base,Value)) of with try file:read_file_info(filename:join(S#xsd_state.xsd_base,Value)) of in the check_anyURI function.
| lib/xmerl/src/xmerl_xsd_type.erl |
| Modified the check_positive_integer function to use try-catch blocks instead of catch blocks to handle exceptions. |
  • Replaced case catch list_to_integer(Value) of with try list_to_integer(Value) of in the check_positive_integer function.
| lib/xmerl/src/xmerl_xsd_type.erl |
| Modified the check_base64Binary function to use try-catch blocks instead of catch blocks to handle exceptions. |
  • Replaced case catch xmerl_b64Bin:parse(xmerl_b64Bin_scan:scan(Value)) of with try xmerl_b64Bin:parse(xmerl_b64Bin_scan:scan(Value)) of in the check_base64Binary function.
| lib/xmerl/src/xmerl_xsd_type.erl |
| Modified the maxInclusive_fun function to use try-catch blocks instead of catch blocks to handle exceptions. |
  • Replaced case (catch list_to_integer(Val) =< list_to_integer(V)) of with try list_to_integer(Val) =< list_to_integer(V) of in the maxInclusive_fun function.
| lib/xmerl/src/xmerl_xsd_type.erl |
| Modified the maxExclusive_fun function to use try-catch blocks instead of catch blocks to handle exceptions. |
  • Replaced case (catch list_to_integer(Val) < list_to_integer(V)) of with try list_to_integer(Val) < list_to_integer(V) of in the maxExclusive_fun function.
| lib/xmerl/src/xmerl_xsd_type.erl |
| Modified the minExclusive_fun function to use try-catch blocks instead of catch blocks to handle exceptions. |
  • Replaced case (catch list_to_integer(Val) > list_to_integer(V)) of with try list_to_integer(Val) > list_to_integer(V) of in the minExclusive_fun function.
| lib/xmerl/src/xmerl_xsd_type.erl |
| Modified the minInclusive_fun function to use try-catch blocks instead of catch blocks to handle exceptions. |
  • Replaced case (catch list_to_integer(Val) >= list_to_integer(V)) of with try list_to_integer(Val) >= list_to_integer(V) of in the minInclusive_fun function.
| lib/xmerl/src/xmerl_xsd_type.erl |
| Modified the scan_number function to use try-catch blocks instead of catch blocks to handle exceptions. |
  • Replaced case catch xmerl_xpath_scan:scan_number(T) of with try {{number, _, N}, Tail} = xmerl_xpath_scan:scan_number(T), in the scan_number function.
| lib/xmerl/src/xmerl_xpath_pred.erl |
| Modified the check_elements function to use try-catch blocks instead of catch blocks to handle exceptions. |
  • Replaced case catch ets:match(Tab,{{elem_def,'_'},'$2'},10) of with try ets:match(Tab,{{elem_def,'_'},'$2'},10) of in the check_elements function.
| lib/xmerl/src/xmerl_scan.erl |
| Modified the scan_reference function to use try-catch blocks instead of catch blocks to handle exceptions. |
  • Replaced case catch scan_entity_ref(T, S) of with try scan_entity_ref(T, S) of in the scan_reference function.
| lib/xmerl/src/xmerl_scan.erl |
| Modified the validate function to use try-catch blocks instead of catch blocks to handle exceptions. |
  • Replaced catch do_validation(read_rules(Rules,Name),XML,Rules,S); with try do_validation(read_rules(Rules,Name),XML,Rules,S) catch in the validate function.
| lib/xmerl/src/xmerl_validate.erl |
| Modified the parse function to use try-catch blocks instead of catch blocks to handle exceptions. |
  • Replaced case catch parse_any(Cont, Rules, S) of with try parse_any(Cont, Rules, S) of in the parse function.
| lib/xmerl/src/xmerl_validate.erl |
| Modified the scanner_options function to use try-catch blocks instead of catch blocks to handle exceptions. |
  • Replaced case catch keyreplace(H, 1, Opts) of with try keyreplace(H, 1, Opts) of in the scanner_options function.
| lib/xmerl/src/xmerl_eventp.erlsrc
lib/xmerl/src/xmerl_simple.erl |
| Modified the parse function to use try-catch blocks instead of catch blocks to handle exceptions. |
  • Replaced case catch reg(S, 0) of with try reg(S, 0) of in the parse function.
| lib/xmerl/src/xmerl_regexp.erl |


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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

Successfully merging this pull request may close these issues.

1 participant