Skip to content

refactor!: Zog issue interface is converted into a struct#119

Merged
Oudwins merged 8 commits intomasterfrom
refactor/zogIssue-as-struct
Mar 6, 2025
Merged

refactor!: Zog issue interface is converted into a struct#119
Oudwins merged 8 commits intomasterfrom
refactor/zogIssue-as-struct

Conversation

@Oudwins
Copy link
Owner

@Oudwins Oudwins commented Mar 6, 2025

Summary by CodeRabbit

  • Refactor

    • Streamlined error processing and reporting for a more consistent experience.
  • Tests

    • Updated test cases to align with improved error message handling and validations.
  • Documentation

    • Enhanced documentation with clearer explanations and updated examples on error management.
  • Chores

    • Removed deprecated internal types and refined APIs for improved maintainability.

These updates deliver a more uniform error reporting approach and ensure that both runtime behavior and documentation remain clear and reliable for end-users.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 6, 2025

Walkthrough

This pull request refactors error handling across the codebase by replacing method calls (e.g., Message()) with direct property access (e.g., Message) in production and test files. Function signatures and struct fields have been updated to use pointers to ZogIssue instead of values, and naming conventions have been aligned. Additionally, documentation and examples have been revised to reflect these changes, clarifying the error management approach without altering the overall control flow.

Changes

Files (Grouped) Change Summary
Test Files: boolean_test.go, conf/issueFormatConf_test.go, errors_test.go, i18n/*_test.go, numbers*_test.go, pointers*_test.go, slices*_test.go, string*_test.go, time*_test.go, struct*_test.go, tutils/testIssueMessages.go Updated assertions to access error messages via the Message field instead of calling methods; parameter types and field names updated to use pointers for ZogIssue; renamed struct fields (e.g., CCode, MsgMessage).
Documentation: docs/docs/core-concepts/1-anatomy-of-schema.md, docs/docs/errors.md, docs/examples-of-use/html-templates.md, docs/examples-of-use/rest-apis.md Reformatted text and code examples; updated field names and removed unnecessary Markdown link formatting; restructured error handling explanations and struct definitions.
Internals & Core Logic: internals/DataProviders.go, internals/Issues.go, internals/contexts.go, internals/pools.go, parsers/zjson/parseJson.go, pointers.go, struct.go Refactored the ZogIssue implementation by replacing the interface with a concrete struct, updating methods to return pointers, simplifying error handling, and separating error checks from assignment logic.
Utilities & Options: utils.go, utilsOptions.go, utilsOptions_test.go Deprecated old error types (ZogErr, etc.) in favor of a consolidated ZogIssue type; introduced helper methods for collecting issues and shifted to direct field access for properties.
ZHTTP Module: zhttp/zhttp.go, zhttp/zhttp_test.go Modified parser functions in the form and query handlers to return pointers to ZogIssue and updated how error messages are accessed in both code and tests.

Sequence Diagram(s)

sequenceDiagram
    participant Test as Test Case
    participant Formatter as Issue Formatter
    participant Issue as ZogIssue
    Test->>Formatter: Invoke formatter with *ZogIssue
    Formatter->>Issue: Access properties (Message, Code)
    Issue-->>Formatter: Return field values
    Formatter-->>Test: Return formatted error message
Loading

Possibly related PRs

Poem

I'm a bunny, skipping through the code,
Hopping over methods in a playful mode.
Fields now shine, no parentheses in sight,
Pointers leap forth, making errors light.
With a twitch of my ears, I cheer with delight—
Refactored paths, a hoppy, bug-free flight!

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@cloudflare-workers-and-pages
Copy link

Deploying zog with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8861cd4
Status: ✅  Deploy successful!
Preview URL: https://d4bcc845.zog-3a0.pages.dev
Branch Preview URL: https://refactor-zogissue-as-struct.zog-3a0.pages.dev

View logs

@Oudwins Oudwins merged commit a68b393 into master Mar 6, 2025
9 of 10 checks passed
@Oudwins Oudwins deleted the refactor/zogIssue-as-struct branch March 6, 2025 07:56
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (11)
conf/issueFormatConf.go (1)

53-53: Update example in documentation comment

The usage example in the comment still shows the old signature func(e p.ZogIssue, c z.Ctx) which should be updated to use a pointer parameter func(e *p.ZogIssue, c z.Ctx) to match the actual implementation.

-conf.IssueFormatter = func(e p.ZogIssue, c z.Ctx) {
+conf.IssueFormatter = func(e *p.ZogIssue, c z.Ctx) {
docs/docs/core-concepts/1-anatomy-of-schema.md (1)

45-46: Grammar and formatting fixes needed in FOOTGUNS section.

The formatting of the FOOTGUNS section has been changed to use blockquotes, but there are some grammatical issues to address.

-> **FOOTGUNS** > _Type Coercion_: Please note that pretransforms are executed before type coercion (if using `schema.Parse()`). This means that if you are responsible for checking that the data matches your expected type. If you blinding typecast the data to, for example, an int and your user provides a string as input you will cause a panic.
-> _Pure Functions_: Since pretransforms are pure functions. A copy of the data is passed in. So if you place a preTransform on a large struct it will copy the entire struct which is not efficient. Be careful!
+> **FOOTGUNS**
+> 
+> _Type Coercion_: Please note that pretransforms are executed before type coercion (if using `schema.Parse()`). This means that you are responsible for checking that the data matches your expected type. If you're blindly typecasting the data to, for example, an int and your user provides a string as input, you will cause a panic.
+>
+> _Pure Functions_: Since pretransforms are pure functions, a copy of the data is passed in. So if you place a preTransform on a large struct, it will copy the entire struct which is not efficient. Be careful!
🧰 Tools
🪛 LanguageTool

[uncategorized] ~45-~45: “you” seems less likely than “you’re” (you are).
Context: ...the data matches your expected type. If you blinding typecast the data to, for exam...

(AI_HYDRA_LEO_CP_YOU_YOUARE)


[uncategorized] ~45-~45: Possible missing comma found.
Context: ... int and your user provides a string as input you will cause a panic. > _Pure Functio...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~46-~46: Possible missing comma found.
Context: ... a large struct it will copy the entire struct which is not efficient. Be careful! ##...

(AI_HYDRA_LEO_MISSING_COMMA)

struct.go (2)

95-103: Improved error handling pattern with clearer variable assignment.

The code has been refactored to use a temporary variable newDp for the factory result, allowing separate error checking before assigning to dataProv. This improves readability by separating the concerns of function calling, error checking, and variable assignment.


104-110: Improved error handling pattern with clearer variable assignment.

Similar to the previous change, this section has been refactored to use a temporary variable newDp instead of directly assigning to dataProv. This makes the code more maintainable and easier to reason about.

internals/DataProviders.go (1)

74-76: Improved nil value handling.

Added a new check for val == nil which now returns an EmptyDataProvider with the underlying value set to val instead of returning an error. This improves the handling of nil values.

Consider adding a unit test for this new code path to ensure nil values are handled correctly.

utils.go (2)

67-67: Minor spelling fix for comment.

Consider changing "Suger" to "Sugar" in your comment for clarity and consistency with standard nomenclature.

-// Suger function that does both sanitize and collect.
+// Sugar function that does both sanitize and collect.

92-97: Minor spelling fix for comment.

As with the earlier comment, "Suger" should be "Sugar" for clarity and consistency.

-// Suger function that does both sanitize and collect.
+// Sugar function that does both sanitize and collect.
docs/docs/errors.md (3)

9-9: Add missing comma after “For example”.

A comma is typically used after “For example” to follow grammar conventions.

-For example the error generated trying to unmarshal...
+For example, the error generated trying to unmarshal...
🧰 Tools
🪛 LanguageTool

[typographical] ~9-~9: After the expression ‘for example’ a comma is usually used.
Context: ...rlying error that caused the issue. For example the error generated trying to unmarshal...

(COMMA_FOR_EXAMPLE)


50-76: Replace hard tabs with spaces.

The markdown lint indicates multiple hard tabs in this section. Converting to spaces can avoid potential alignment issues across editors.

-<TAB>ISSUE_KEY_FIRST = "$first"
+    ISSUE_KEY_FIRST = "$first"

(And similarly for other lines flagged by the linter.)

🧰 Tools
🪛 markdownlint-cli2 (0.17.2)

54-54: Hard tabs
Column: 1

(MD010, no-hard-tabs)


55-55: Hard tabs
Column: 1

(MD010, no-hard-tabs)


56-56: Hard tabs
Column: 1

(MD010, no-hard-tabs)


57-57: Hard tabs
Column: 1

(MD010, no-hard-tabs)


58-58: Hard tabs
Column: 1

(MD010, no-hard-tabs)


59-59: Hard tabs
Column: 1

(MD010, no-hard-tabs)


60-60: Hard tabs
Column: 1

(MD010, no-hard-tabs)


61-61: Hard tabs
Column: 1

(MD010, no-hard-tabs)


62-62: Hard tabs
Column: 1

(MD010, no-hard-tabs)


63-63: Hard tabs
Column: 1

(MD010, no-hard-tabs)


64-64: Hard tabs
Column: 1

(MD010, no-hard-tabs)


65-65: Hard tabs
Column: 1

(MD010, no-hard-tabs)


66-66: Hard tabs
Column: 1

(MD010, no-hard-tabs)


67-67: Hard tabs
Column: 1

(MD010, no-hard-tabs)


68-68: Hard tabs
Column: 1

(MD010, no-hard-tabs)


69-69: Hard tabs
Column: 1

(MD010, no-hard-tabs)


70-70: Hard tabs
Column: 1

(MD010, no-hard-tabs)


71-71: Hard tabs
Column: 1

(MD010, no-hard-tabs)


72-72: Hard tabs
Column: 1

(MD010, no-hard-tabs)


73-73: Hard tabs
Column: 1

(MD010, no-hard-tabs)


80-80: Add period after “etc.”

In American English, abbreviations like “etc.” customarily include a period.

-... the path, params, etc)
+... the path, params, etc.)
🧰 Tools
🪛 LanguageTool

[style] ~80-~80: In American English, abbreviations like “etc.” require a period.
Context: ...hat caused the issue, the path, params, etc). ```go errs := userSchema.Parse(data,...

(ETC_PERIOD)

internals/Issues.go (1)

93-95: Reset fields before pooling if necessary.
FreeIssue(i *ZogIssue) calls ZogIssuePool.Put(i), but the code does not appear to reset individual fields. Consider clearing or zeroing out i’s fields (e.g., i.Code = 0, i.Value = nil) to prevent data contamination in future reuses.

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fcfc1ab and 8861cd4.

📒 Files selected for processing (37)
  • boolean_test.go (1 hunks)
  • conf/issueFormatConf.go (1 hunks)
  • conf/issueFormatConf_test.go (1 hunks)
  • docs/docs/core-concepts/1-anatomy-of-schema.md (3 hunks)
  • docs/docs/errors.md (5 hunks)
  • docs/docs/examples-of-use/html-templates.md (2 hunks)
  • docs/docs/examples-of-use/rest-apis.md (1 hunks)
  • errors_test.go (1 hunks)
  • i18n/i18n.go (1 hunks)
  • i18n/i18n_test.go (2 hunks)
  • internals/DataProviders.go (3 hunks)
  • internals/Issues.go (3 hunks)
  • internals/contexts.go (5 hunks)
  • internals/pools.go (2 hunks)
  • numbers_int64_test.go (8 hunks)
  • numbers_test.go (8 hunks)
  • numbers_validate_test.go (8 hunks)
  • parsers/zjson/parseJson.go (2 hunks)
  • pointers.go (2 hunks)
  • pointers_test.go (3 hunks)
  • pointers_validate_test.go (1 hunks)
  • slices_test.go (4 hunks)
  • slices_validate_test.go (2 hunks)
  • string_test.go (9 hunks)
  • string_validate_test.go (10 hunks)
  • struct.go (1 hunks)
  • struct_helper_test.go (10 hunks)
  • struct_test.go (4 hunks)
  • struct_validate_test.go (3 hunks)
  • time_test.go (5 hunks)
  • time_validate_test.go (5 hunks)
  • tutils/testIssueMessages.go (1 hunks)
  • utils.go (4 hunks)
  • utilsOptions.go (1 hunks)
  • utilsOptions_test.go (3 hunks)
  • zhttp/zhttp.go (1 hunks)
  • zhttp/zhttp_test.go (1 hunks)
✅ Files skipped from review due to trivial changes (1)
  • struct_helper_test.go
🧰 Additional context used
🪛 LanguageTool
docs/docs/core-concepts/1-anatomy-of-schema.md

[uncategorized] ~45-~45: “you” seems less likely than “you’re” (you are).
Context: ...the data matches your expected type. If you blinding typecast the data to, for exam...

(AI_HYDRA_LEO_CP_YOU_YOUARE)


[uncategorized] ~45-~45: Possible missing comma found.
Context: ... int and your user provides a string as input you will cause a panic. > _Pure Functio...

(AI_HYDRA_LEO_MISSING_COMMA)


[uncategorized] ~46-~46: Possible missing comma found.
Context: ... a large struct it will copy the entire struct which is not efficient. Be careful! ##...

(AI_HYDRA_LEO_MISSING_COMMA)

docs/docs/errors.md

[typographical] ~9-~9: After the expression ‘for example’ a comma is usually used.
Context: ...rlying error that caused the issue. For example the error generated trying to unmarshal...

(COMMA_FOR_EXAMPLE)


[style] ~80-~80: In American English, abbreviations like “etc.” require a period.
Context: ...hat caused the issue, the path, params, etc). ```go errs := userSchema.Parse(data,...

(ETC_PERIOD)

🪛 markdownlint-cli2 (0.17.2)
docs/docs/errors.md

15-15: Heading levels should only increment by one level at a time
Expected: h3; Actual: h6

(MD001, heading-increment)


54-54: Hard tabs
Column: 1

(MD010, no-hard-tabs)


55-55: Hard tabs
Column: 1

(MD010, no-hard-tabs)


56-56: Hard tabs
Column: 1

(MD010, no-hard-tabs)


57-57: Hard tabs
Column: 1

(MD010, no-hard-tabs)


58-58: Hard tabs
Column: 1

(MD010, no-hard-tabs)


59-59: Hard tabs
Column: 1

(MD010, no-hard-tabs)


60-60: Hard tabs
Column: 1

(MD010, no-hard-tabs)


61-61: Hard tabs
Column: 1

(MD010, no-hard-tabs)


62-62: Hard tabs
Column: 1

(MD010, no-hard-tabs)


63-63: Hard tabs
Column: 1

(MD010, no-hard-tabs)


64-64: Hard tabs
Column: 1

(MD010, no-hard-tabs)


65-65: Hard tabs
Column: 1

(MD010, no-hard-tabs)


66-66: Hard tabs
Column: 1

(MD010, no-hard-tabs)


67-67: Hard tabs
Column: 1

(MD010, no-hard-tabs)


68-68: Hard tabs
Column: 1

(MD010, no-hard-tabs)


69-69: Hard tabs
Column: 1

(MD010, no-hard-tabs)


70-70: Hard tabs
Column: 1

(MD010, no-hard-tabs)


71-71: Hard tabs
Column: 1

(MD010, no-hard-tabs)


72-72: Hard tabs
Column: 1

(MD010, no-hard-tabs)


73-73: Hard tabs
Column: 1

(MD010, no-hard-tabs)


98-98: Hard tabs
Column: 1

(MD010, no-hard-tabs)


99-99: Hard tabs
Column: 1

(MD010, no-hard-tabs)


100-100: Hard tabs
Column: 1

(MD010, no-hard-tabs)


101-101: Hard tabs
Column: 1

(MD010, no-hard-tabs)


102-102: Hard tabs
Column: 1

(MD010, no-hard-tabs)


103-103: Hard tabs
Column: 1

(MD010, no-hard-tabs)


104-104: Hard tabs
Column: 1

(MD010, no-hard-tabs)


105-105: Hard tabs
Column: 1

(MD010, no-hard-tabs)


106-106: Hard tabs
Column: 1

(MD010, no-hard-tabs)


107-107: Hard tabs
Column: 1

(MD010, no-hard-tabs)


108-108: Hard tabs
Column: 1

(MD010, no-hard-tabs)


109-109: Hard tabs
Column: 1

(MD010, no-hard-tabs)


110-110: Hard tabs
Column: 1

(MD010, no-hard-tabs)


111-111: Hard tabs
Column: 1

(MD010, no-hard-tabs)


112-112: Hard tabs
Column: 1

(MD010, no-hard-tabs)


113-113: Hard tabs
Column: 1

(MD010, no-hard-tabs)


114-114: Hard tabs
Column: 1

(MD010, no-hard-tabs)


115-115: Hard tabs
Column: 1

(MD010, no-hard-tabs)


120-120: Hard tabs
Column: 1

(MD010, no-hard-tabs)


121-121: Hard tabs
Column: 1

(MD010, no-hard-tabs)


126-126: Hard tabs
Column: 1

(MD010, no-hard-tabs)


127-127: Hard tabs
Column: 1

(MD010, no-hard-tabs)


132-132: Hard tabs
Column: 1

(MD010, no-hard-tabs)


133-133: Hard tabs
Column: 1

(MD010, no-hard-tabs)


138-138: Hard tabs
Column: 1

(MD010, no-hard-tabs)


139-139: Hard tabs
Column: 1

(MD010, no-hard-tabs)


144-144: Hard tabs
Column: 1

(MD010, no-hard-tabs)


145-145: Hard tabs
Column: 1

(MD010, no-hard-tabs)


150-150: Hard tabs
Column: 1

(MD010, no-hard-tabs)


151-151: Hard tabs
Column: 1

(MD010, no-hard-tabs)


156-156: Hard tabs
Column: 1

(MD010, no-hard-tabs)


157-157: Hard tabs
Column: 1

(MD010, no-hard-tabs)


162-162: Hard tabs
Column: 1

(MD010, no-hard-tabs)


167-167: Hard tabs
Column: 1

(MD010, no-hard-tabs)

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (91)
docs/docs/examples-of-use/rest-apis.md (1)

10-15: Documentation enhancement - clear examples for both Parse and Validate approaches.

The additions improve the documentation by clearly showing two different approaches to handling form data:

  1. Using Parse to unmarshal and validate in one step
  2. Using a separate unmarshalling step followed by explicit validation with Validate

This gives users more flexibility in how they integrate Zog into their existing code.

tutils/testIssueMessages.go (2)

16-22: Updated error property access pattern.

The changes correctly replace method calls with direct field access to ZogIssue struct fields, which aligns with the PR objective of converting the Zog issue interface into a struct.


29-30: Updated error message assertion.

Consistent with the other changes, error message assertions now use direct field access instead of method calls.

docs/docs/examples-of-use/html-templates.md (2)

25-25: API simplification.

Changed from zhttp.NewRequestDataProvider(r) to the more concise zhttp.Request(r), which makes the API more intuitive and reduces verbosity.


37-37: Updated error property access pattern.

Changed from using method calls (e[0].Message()) to direct field access (e[0].Message), consistent with the PR objective of converting the Zog issue interface into a struct.

Also applies to: 42-42

pointers.go (2)

62-67: Improved error handling.

The error handling logic has been refined to ensure that the context value (ctx.Val) is only updated after confirming that fn() executes without error. This prevents the context from being updated with potentially invalid data.


24-25:

Details

✅ Verification successful

Type determination delegation.

Changed from returning a fixed pointer type to delegating the type determination to the underlying schema. This is a significant behavioral change that affects type-related functionality throughout the system.

Let's check how this change impacts other parts of the codebase:


🏁 Script executed:

#!/bin/bash
# Search for places where the getType method is called/used
rg -A 3 "getType\(\)" --type go

Length of output: 5884


Type determination delegation verified

The change in pointers.go—switching from returning a fixed zconst.TypePtr to delegating type determination via v.schema.getType()—has been verified. The search results confirm that:

  • The new delegation pattern is consistent, with getType() calls in pointers.go and elsewhere now correctly routing through the underlying schema.
  • Other schema types (e.g., in boolean.go, numbers.go, slices.go, etc.) continue to use their respective fixed type constants, while the pointer schema now aligns its type with its wrapped schema.
  • The tests (e.g., in boolean_test.go, numbers_test.go, and others) validate the expected type outputs, ensuring no breaking changes in downstream functionality.

Overall, this delegation is intentional and systematically applied across the codebase. Please ensure that downstream integrations are thoroughly tested, as this change significantly alters the way pointer types are determined.

zhttp/zhttp_test.go (1)

314-314: Field access updated to match ZogIssue struct refactoring

This change reflects the refactoring from accessing error code via a method call (err.Code()) to directly accessing the field property (err.Code), aligning with the conversion of ZogIssue from an interface to a struct.

i18n/i18n.go (1)

26-26: Parameter type updated to use pointer receiver

The parameter type for IssueFormatter has been changed from a value type to a pointer type (*internals.ZogIssue). This change is consistent with the refactoring across the codebase, allowing direct modification of the ZogIssue instance.

internals/pools.go (2)

34-34: Type renamed from ZogErr to ZogIssue

The object pool now returns &ZogIssue{} instead of &ZogErr{}, establishing consistency in naming across the codebase as part of the refactoring.


85-85: Type renamed from ZogErr to ZogIssue

Similarly updated in the ClearPools function to maintain consistency with the renaming from ZogErr to ZogIssue throughout the codebase.

utilsOptions.go (1)

15-15: Updated to use pointer receiver for ZogIssue

Changed the parameter type from ZogIssue to *ZogIssue to align with the codebase-wide refactoring of treating ZogIssue as a struct with direct field access rather than an interface with methods.

boolean_test.go (1)

130-131: Good refactoring: Updated to use Message field directly.

The test logic now correctly accesses the error message as a direct property instead of using a method call, consistent with the ZogIssue interface to struct conversion mentioned in the PR objectives.

time_validate_test.go (1)

20-20: Consistent updates to error message access.

All assertions now correctly access the Message field directly rather than calling a method. This consistent pattern reflects the ZogIssue interface to struct conversion.

Also applies to: 89-89, 101-101, 113-113, 123-123

string_test.go (1)

119-119: Thorough refactoring of error assertions.

All error message assertions throughout the test file have been systematically updated to use the direct property access pattern (errs[0].Message instead of method calls), keeping the test functionality identical while aligning with the new struct-based approach.

Also applies to: 129-129, 272-272, 286-286, 300-300, 314-314, 324-324, 329-329, 334-334, 343-343, 361-361

slices_test.go (2)

45-45: API simplification: Direct data passing to Parse method.

The Parse API has been simplified by allowing direct data passing instead of wrapping it with a provider. This is a good usability improvement that makes the API more intuitive.

Also applies to: 57-57


86-86: Updated error message access pattern.

Consistent with other files, error message assertions now use direct property access instead of method calls, maintaining the same behavior while following the new struct-based approach.

Also applies to: 232-232

time_test.go (1)

19-19: Consistent refactoring of error message access

The changes from errs[0].Message() to errs[0].Message align with the PR's objective of converting ZogIssue from an interface to a struct, enabling direct field access instead of method calls.

Also applies to: 97-97, 107-107, 118-118, 128-128

zhttp/zhttp.go (1)

31-31: Appropriate use of pointers for ZogIssue return types

The changes from returning ZogIssue by value to returning *ZogIssue pointers are a good practice that:

  1. Avoids unnecessary copying of error data
  2. Allows for mutation of error objects after creation if needed
  3. Aligns with idiomatic Go error handling patterns

The struct initialization at line 34 also shows the clean syntax benefit of using a struct versus an interface.

Also applies to: 34-34, 40-40

numbers_test.go (2)

22-22: Parameter type correctly updated to pointer receiver

Changing the WithIssueFormatter parameter from ZogIssue to *ZogIssue is appropriate since the function needs to modify the error by calling e.SetMessage(). Using a pointer parameter provides both better performance and necessary mutability.


27-27: Consistent conversion from method calls to field access

All assertions have been systematically updated from errs[0].Message() to errs[0].Message, maintaining consistency with the ZogIssue interface-to-struct conversion throughout the codebase.

Also applies to: 30-30, 68-68, 74-74, 80-80, 187-187, 202-202, 217-217, 222-222, 241-241, 256-256, 261-261, 280-280

conf/issueFormatConf.go (1)

26-27: Appropriate parameter type change and field access conversion

The formatter function now correctly:

  1. Uses *p.ZogIssue pointer parameter, which is necessary since it modifies the error object
  2. Accesses ZogIssue fields directly instead of through method calls, consistent with the struct conversion

These changes maintain the same functionality while improving the code structure.

Also applies to: 31-32, 37-37, 40-40

numbers_int64_test.go (2)

22-22: Parameter type change is consistent with ZogIssue refactoring.

The function parameter has been changed from a value receiver to a pointer receiver, which is consistent with the conversion of ZogIssue from an interface to a struct.


27-27: Accessing Message as a property instead of method call.

The change from method calls (errs[0].Message()) to property access (errs[0].Message) is consistent with the ZogIssue interface being converted to a struct. This pattern is applied consistently throughout all error message checks in this file.

Also applies to: 30-30, 57-57, 63-63, 69-69, 175-175, 190-190, 205-205, 210-210, 229-229, 244-244, 249-249, 268-268

string_validate_test.go (1)

125-125: Consistent property access pattern for error messages.

All error message assertions have been updated to access Message as a property rather than a method call, which aligns with the broader refactoring of the ZogIssue interface into a struct.

Also applies to: 134-134, 273-273, 288-288, 303-303, 318-318, 333-333, 344-344, 353-353, 373-373

pointers_validate_test.go (2)

29-29: Parameter type change to pointer receiver for ZogIssue.

The function parameter was changed from ZogIssue to *ZogIssue, consistent with the conversion of ZogIssue from an interface to a struct and enabling in-place modifications.


34-34: Updated error message access pattern.

The assertions have been updated to access Message as a property rather than a method call, maintaining consistency with the ZogIssue refactoring throughout the codebase.

Also applies to: 37-37

docs/docs/core-concepts/1-anatomy-of-schema.md (1)

22-22: Simplified field declaration in documentation.

The Markdown link formatting was removed from the field declaration (tests: []Test instead of [tests](#tests): []Test), making the example struct definition cleaner and more straightforward.

numbers_validate_test.go (2)

22-22: Function parameter type updated to reflect ZogIssue refactoring.

The parameter type has been changed from ZogIssue to *ZogIssue which aligns with the refactoring of ZogIssue from an interface to a struct. Using pointers is more efficient when working with structs.


27-27: Direct field access replaces method calls on ZogIssue.

Changed from using errs[0].Message() to errs[0].Message, which is consistent with the refactoring of ZogIssue from an interface with methods to a struct with fields. This provides more direct and potentially more efficient access to the error message.

Also applies to: 30-30, 47-47, 157-157, 173-173, 189-189, 195-195, 216-216, 232-232, 238-238, 259-259

slices_validate_test.go (2)

177-177: Direct field access replaces method calls on ZogIssue.

Changed from using errs["$root"][0].Message() to errs["$root"][0].Message, which is consistent with the refactoring of ZogIssue from an interface with methods to a struct with fields.


228-229: Renamed from Errors to Issues for more appropriate semantics.

Changed references from Errors.SanitizeList to Issues.SanitizeList, providing more accurate terminology. This is a good change that improves code readability and reflects the actual purpose of the functionality more clearly.

Also applies to: 235-236

conf/issueFormatConf_test.go (3)

13-13: Updated test input type to use pointer to ZogIssue.

Changed the test input type from p.ZogIssue to *p.ZogIssue, aligning with the overall refactoring of ZogIssue from an interface to a struct that's passed by reference.


16-18: Updated test data to use new ZogIssue struct fields.

Test cases have been updated to use the new ZogIssue struct with properly named fields (Code, Dtype, Message) instead of the previous abbreviated names (C, Typ, Msg). This improves code readability and makes the field purposes more obvious.


23-23: Direct field access replaces method calls for ZogIssue.

Access pattern changed from test.input.Message() to test.input.Message, which is consistent with the refactoring of ZogIssue from an interface with methods to a struct with fields.

struct_test.go (4)

54-54: API simplification looks good.

The change from using NewMapDataProvider(data) to passing data directly to Parse simplifies the API usage. This is a nice improvement that reduces unnecessary wrapping.


70-70: Consistent API simplification.

Similar to the change at line 54, this also simplifies the API by passing data directly to Parse.


103-103: Consistent API simplification.

Direct parsing of map data without wrapping in a data provider, consistent with previous changes.


188-188: Changed from method call to field access.

The change from errs["$root"][0].Message() to errs["$root"][0].Message represents the conversion from interface method to struct field access, aligning with the PR objective.

i18n/i18n_test.go (3)

96-96: Changed from method call to field access.

The change from nameErrs[0].Message() to nameErrs[0].Message aligns with the new struct-based approach rather than interface methods.


101-101: Consistent field access pattern.

Similar to line 96, this changes from method call Message() to direct field access Message.


123-123: Consistent field access pattern.

Changed from errs[0].Message() to errs[0].Message, maintaining consistency with the struct-based approach.

parsers/zjson/parseJson.go (3)

36-36: Return type changed to pointer for ZogIssue.

The return signature has been updated from (p.DataProvider, p.ZogIssue) to (p.DataProvider, *p.ZogIssue), which aligns with the change from interface to struct. Using a pointer is more efficient for structs.


45-45: Using ZogIssue struct instead of ZogErr.

The change from &p.ZogErr{C: zconst.IssueCodeInvalidJSON, Err: err} to &p.ZogIssue{Code: zconst.IssueCodeInvalidJSON, Err: err} standardizes on a single error type and uses more descriptive field names.


48-48: Consistent use of ZogIssue struct.

Similar to line 45, this standardizes on using the ZogIssue struct with descriptive field names.

struct_validate_test.go (3)

139-139: Changed from method call to field access.

The change from errs["num"][0].Code() to errs["num"][0].Code aligns with the new struct-based approach rather than interface methods.


160-161: Consistent field access pattern.

Both error property accesses have been updated from method calls to direct field access (Code() to Code and Message() to Message), which is consistent with the struct-based approach.


235-235: Consistent field access pattern.

Changed from errs["somefield"][0].Code() to errs["somefield"][0].Code, maintaining consistency with the struct-based approach.

errors_test.go (2)

12-18: Field renaming and type refactoring looks good.

The refactoring from ZogErr to ZogIssue with more descriptive field names (like Code instead of C, Message instead of Msg) improves code readability. The change to pointer type (*p.ZogIssue) is consistent with the PR objective of converting the issue interface into a struct.


24-26: Type change is consistent.

The change to use *p.ZogIssue is consistent with the earlier test case and aligns with the overall PR objective.

utilsOptions_test.go (5)

20-22: Function signature changed appropriately.

The parameter type for the WithIssueFormatter function has been updated to accept a pointer (*p.ZogIssue) instead of a value, which is consistent with the refactoring approach.


24-26: Struct type and field name refactoring.

The change from ZogErr to ZogIssue and from EPath to Path follows better naming conventions and improves readability.


28-28: Direct field access instead of method call.

Changed from method call (err.Message()) to direct field access (err.Message), which is consistent with the conversion from interface to struct.


33-35: Function signature updated consistently.

The MessageFunc parameter type has been updated to use a pointer, which is consistent with the other refactoring changes.


37-38: Direct field access pattern applied consistently.

All assertions have been updated to use direct field access (err[0].Message, err[0].Code) instead of method calls, which is consistent with the interface-to-struct conversion.

Also applies to: 46-47, 52-53, 70-72, 77-79

internals/DataProviders.go (2)

8-8: Return type changed to pointer.

The DpFactory type now returns a pointer to ZogIssue instead of a value. This is a breaking change but is consistent with the PR objective of refactoring the issue interface into a struct.


105-105: Simplified error handling for nil pointers.

The error handling for nil pointers has been simplified to just return an EmptyDataProvider without an error message. This is consistent with the improved nil handling approach in this refactoring.

pointers_test.go (6)

36-38: Function signature updated consistently.

The WithIssueFormatter function has been updated to accept a pointer to ZogIssue instead of a value, maintaining consistency with the refactoring approach.


41-42: Direct field access pattern applied consistently.

All assertions have been updated to use direct field access (.Message, .Code) instead of method calls, which is consistent with the interface-to-struct conversion.

Also applies to: 44-45, 92-93, 192-193


80-82: Added new field to test structure.

A new field Value2 has been added to the TestStruct type, which enhances test coverage.


85-87: Schema validation enhanced.

The schema has been updated to include a NotNil() constraint for the value field and added validation for the new value2 field. This improves test coverage.


95-96: Added assertion for new field.

An assertion has been added to verify that the Value2 field is correctly initialized to nil. This is consistent with the added field in the test structure.


97-100: Updated test input data.

The input map has been updated to include a value for the new value2 field, which properly tests the enhanced schema validation.

utils.go (6)

20-21: Refactor awareness: ZogIssue aliasing looks good.

Defining the ZogIssue alias in place of the old types is consistent with the refactor objective. Good job keeping it succinct and clearly documented.


76-81: Good use of Collect after Sanitize.

This helper method nicely combines two operations. The approach is straightforward, and there do not appear to be any issues.


83-90: Switching to direct field access looks appropriate.

Using err.Message directly instead of a method call is consistent with the new struct-based approach to issues.


99-104: Smart memory reuse approach.

The use of CollectMap to "free" Zog issues in the map is a good approach to optimize memory usage. Ensure that these freed objects aren't used concurrently to avoid data races.


106-111: Potential concurrency caution.

Similar to CollectMap, ensure that CollectList usage only occurs under safe conditions to prevent reusing issues still in use elsewhere.


113-115: Confirm concurrency safety in pooled usage.

Freeing or pooling ZogIssue instances can yield performance benefits, but confirm that there’s no risk of multiple goroutines referencing the same freed struct. If concurrency is possible, a synchronization approach is recommended.

docs/docs/errors.md (2)

246-247: Pointer-based signature matches the updated struct approach.

Changing IssueFmtFunc to accept *ZogIssue aligns with your pointer-based refactor. This looks consistent throughout the codebase.


300-301: Custom issue formatter caution.

Overriding conf.IssueFormatter can yield uniform or surprising results. If not done carefully, all issues may receive the same message. Looks correct for advanced usage, but proceed with caution.

internals/contexts.go (11)

13-15: Pointer-based methods for error addition.

Switching from value to pointer for NewError and AddIssue is consistent with your new struct-based pattern. No issues here.


53-54: Ensure the fallback formatter is always present.

In cases where e.Message is empty, calling c.Fmter(e, c) is crucial. Double-check that c.Fmter is never nil to avoid panics.


62-63: Deprecated method usage is well-handled.

Using NewError to invoke an internal addition of issues maintains backward compatibility. Good approach.


67-68: No concerns with FmtErr usage.

Formatting remains consistent, and the short-circuit check for e.Message != "" is sensible.


116-125: Pooling approach can be efficient but verify concurrency usage.

Grabbing an issue from a pool, resetting its fields, and returning the pointer is efficient. Just ensure all references are local to one goroutine at a time.


130-138: Consistent IssueFromTest logic.

Setting the code, path, params, and message to defaults or test-based values is intuitive. This aligns well with pointer semantics.


149-155: Coercion error usage.

Creating a brand-new ZogIssue for a coercion error is clear. The approach fully resets message, code, and path as intended.


162-163: Reusing the existing ZogIssue if possible.

Wrapping unknown errors in a new issue while reusing err if it’s already a *ZogIssue is a neat approach. No concerns here.


175-185: TestCtx integration looks correct.

Extracting another ZogIssue from the pool and applying the test’s code and params is consistent with the rest of the refactor.


188-189: Formatter fallback logic.

Checks for an existing message, then calls c.Test.IssueFmtFunc(e, c), and ultimately falls back to the schema’s FmtErr. Good layered design.


201-201: Maintains consistent pointer-based approach.

AddIssue(e *ZogIssue) in TestCtx ensures the message is properly formatted before adding to errors. This matches the updated interface.

internals/Issues.go (9)

10-10: No concerns with function type alias.
The introduction of this IssueFmtFunc type alias referencing ZogIssue appears straightforward and consistent with the updated struct-based design.


12-15: Good, clear documentation.
The doc comment clearly outlines the purpose and usage of ZogIssue. This helps maintain clarity for future maintainers.


16-34: Ensure sensitive data is handled properly.
While this struct is labeled “safe to expose to the user,” the Value any field could inadvertently hold sensitive or PII data. Verify that there are no edge cases where internal or sensitive details leak to user-facing logs or messages.


36-76: Setters and method chaining are implemented consistently.
All setter methods follow a uniform pattern, returning *ZogIssue for easy chaining. The logic is clear and correct, with no immediate pitfalls or concurrency concerns.


78-92: Error and String methods align with Go’s error interface.
Unwrap(), Error(), and String() methods implement error unwrapping and string formatting as expected, facilitating straightforward error handling.


98-101: Straightforward alias for list of issues.
type ZogIssueList = []*ZogIssue is consistent with the move to pointer-based usage of ZogIssue. No immediate problems identified.


105-105: Interface signature update is coherent.
Accepting *ZogIssue in the Add method aligns with the new struct-based approach, preserving consistency across the codebase.


122-122: Appending to the list remains simple and clear.
Storing incoming issues in ErrsList is correctly handled. No concurrency or logical issues observed here.


149-164: Logic for marking the first error looks intentional.
Storing the first issue under zconst.ISSUE_KEY_FIRST can be helpful for quick access to the lead error. Ensure you have sufficient test coverage confirming that the correct “root” or “first” entries are retained in ErrsMap.

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.

1 participant