[Feature/53] :: fix critical data gen#54
Conversation
|
Note Reviews pausedIt looks like this branch is under active development. To avoid overwhelming you with review comments due to an influx of new commits, CodeRabbit has automatically paused this review. You can configure this behavior by changing the Use the following commands to manage reviews:
Use the checkboxes below for quick actions:
📝 WalkthroughWalkthroughRefactors generators to return plain localized error messages (removing sentinel wrapping), adds a concurrency-safe RandSource wrapper and uses it in Mocker, exposes phone generation via Mocker, updates address UF selection to use a UF map with fallbacks, and adds localized docs about error-message localization. Changes
Sequence Diagram(s)sequenceDiagram
participant Client
participant Mocker
participant SafeRand as SafeRandSource (translations)
participant Phone as phone.NewPhone
Client->>Mocker: NewMocker(lang,isFormatted,rnd)
alt rnd == nil
Mocker->>SafeRand: defaultRandSource() -> NewSafeRandSource(rand.New(...))
else rnd != nil
Mocker->>SafeRand: NewSafeRandSource(rnd)
end
Client->>Mocker: NewPhone()
Mocker->>Phone: phone.NewPhone(m.lang, m.rnd)
Phone->>SafeRand: Intn(...) (thread-safe)
Phone-->>Mocker: (*phone.Phone, nil) or (error with localized message)
Mocker-->>Client: return result
sequenceDiagram
participant Caller
participant AddressGen as address.generateAddress
participant Translations as translations.GetUFMap
participant Lists as translations.GetList/GetRandom
Caller->>AddressGen: generateAddress(lang, rnd)
AddressGen->>Translations: GetUFMap(lang)
alt UF map available
AddressGen->>Lists: select states list -> pick stateIdx
AddressGen->>Lists: derive uf = ufMap[state]
else UF map absent
AddressGen->>Lists: pick state and uf from lists (fallbacks)
end
AddressGen-->>Caller: address or localized error (no sentinel wrapping)
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~22 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 1 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (1 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
Actionable comments posted: 6
🧹 Nitpick comments (4)
pkg/mocai/translations/safe_rand.go (1)
11-13: Consider guarding against double-wrapping.If a caller passes an already-wrapped
*SafeRandSourcetoNewMocker, it gets wrapped again, creating unnecessary nested mutexes. While not a correctness bug, it adds overhead.♻️ Proposed fix to avoid double-wrapping
func NewSafeRandSource(rnd RandSource) *SafeRandSource { + // Avoid double-wrapping if already a SafeRandSource + if safe, ok := rnd.(*SafeRandSource); ok { + return safe + } return &SafeRandSource{rnd: rnd} }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/mocai/translations/safe_rand.go` around lines 11 - 13, The constructor NewSafeRandSource should avoid double-wrapping an already-safe source: in NewSafeRandSource check whether the incoming rnd is already a *SafeRandSource (type assertion) and if so return it directly instead of creating a new wrapper; update callers like NewMocker (or any code that passes a RandSource) to rely on this behavior so you don't nest mutexes unnecessarily.pkg/mocai/entities/phone/generator.go (1)
32-34: Defensive check is useful but could be more specific.This check guards against empty strings in the area code data, which is valuable. However, unlike the address generator which validates all list items upfront with
strings.TrimSpace(), this validation only catches the specific selected value. Consider adding upfront validation similar toaddress/generator.golines 55-59 for consistency, or document why this lighter check is sufficient.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/mocai/entities/phone/generator.go` around lines 32 - 34, The area code empty-string check is too narrow—before selecting an areaCode, validate and trim the entire areaCodes slice (e.g., iterate over areaCodes and apply strings.TrimSpace, removing or rejecting empty entries) similar to address/generator.go's upfront validation so you never pick an empty value; update the generator function that sets areaCodes/areaCode to perform this sanitization and only proceed if there is at least one non-empty trimmed area code, otherwise return the same translations.Get(lang, "error_generating_phone") error.pkg/mocai/entities/address/generator.go (2)
68-81: RedundantGetUFMapcall and index alignment assumption.Two observations:
GetUFMap(supportedLang)is called twice (line 36 and 68). Consider reusing the result from line 36.Line 74-75 assumes the
address_uflist is index-aligned with theaddress_statelist. If these lists have different orderings or lengths, the pairing will be incorrect. The map-based lookup (line 70) is more robust.♻️ Proposed fix to reuse GetUFMap result
func generateAddress(lang string, rnd translations.RandSource) (*Address, error) { - supportedLang := lang - if translations.GetUFMap(lang) == nil { + ufMap := translations.GetUFMap(lang) + supportedLang := lang + if ufMap == nil { supportedLang = "ptbr" + ufMap = translations.GetUFMap(supportedLang) } streets := translations.GetList(supportedLang, "address_street") ... - ufMap := translations.GetUFMap(supportedLang) if ufMap != nil { uf = ufMap[state] }🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/mocai/entities/address/generator.go` around lines 68 - 81, Reuse the already-obtained UF map instead of calling translations.GetUFMap(supportedLang) again (use the existing ufMap variable), and avoid assuming address_uf list alignment with address_state: when ufMap is nil, do not index address_uf by stateIdx; instead try to find a matching UF by locating the state's index in the address_state list or build a map from the address_state and address_uf lists to look up by state, and only fall back to a random selection from address_uf if no match is found; update code that references ufMap, uf, stateIdx, state, translations.GetUFMap and translations.GetList accordingly.
35-42: Silent language fallback may cause unexpected behavior.When
GetUFMap(lang)returnsnil(currently all languages except "ptbr"), the function silently falls back to Brazilian Portuguese data. This means a caller requestinglang="en"would receive Brazilian addresses without any indication that their requested language wasn't supported.Consider either:
- Returning an error for unsupported languages
- Logging a warning when fallback occurs
- Documenting this behavior in the function's doc comment
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/mocai/entities/address/generator.go` around lines 35 - 42, The code silently falls back to "ptbr" when translations.GetUFMap(lang) == nil; change this so unsupported languages are not silent: when GetUFMap(lang) returns nil, emit a warning (use the package logger or returned error path) that includes the requested lang and that you're falling back to "ptbr", and update the function doc comment to document this fallback behavior (or alternatively change the function to return an error instead of falling back). Ensure the check around supportedLang/GetUFMap(lang) and subsequent calls to translations.GetList(supportedLang, "address_*") reference the same variables (supportedLang, GetUFMap) so the warning/error is emitted before using translations.GetList.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@docs/localization/pt/README-PT.md`:
- Around line 89-96: The "Mensagens de Erro e Localização" prose is inside the
Go code fence because it appears before the closing brace and closing code fence
of main(); move that entire markdown section so it appears after the closing
code block (after the final ``` and the closing `}` of main()), ensuring the
code block is properly closed and the documentation renders as regular markdown;
verify references to functions like main(), NewPerson(), and NewAddress() remain
in backticks in the moved section.
In `@pkg/mocai/entities/certificate/countries/brazilian_certificates.go`:
- Around line 106-107: Replace the sentinel ErrInvalidPageNumber return with the
localized pattern used elsewhere: change the line returning ErrInvalidPageNumber
to return nil, translations.Get(...) using the same translation key format used
in the surrounding checks (match the exact key used on lines ~96, ~103, ~111,
~116, ~125) so the function returns a localized error via translations.Get
instead of the raw ErrInvalidPageNumber sentinel.
In `@pkg/mocai/entities/cpf/generator.go`:
- Around line 37-38: The code replaced a sentinel error (ErrInvalidCPF) with a
localized string, breaking errors.Is checks and leaving ErrInvalidCPF unused;
update the return in the CPF generator so the sentinel is preserved by wrapping
the localized message (use fmt.Errorf with %w combining cpf.ErrInvalidCPF and
translations.Get(lang, "invalid_cpf")), keep the existing cpfNumber length check
and ErrInvalidCPF symbol, and then sweep other entity generators (phone, vote,
person) to either similarly wrap their sentinels or remove the now-orphaned Err*
sentinels in errors.go if you intentionally want to drop programmatic sentinel
checks.
In
`@pkg/mocai/entities/voteregistration/countries/brazilian_vote_registration.go`:
- Around line 146-156: The constructors are inconsistent: update
NewBrazilianVoteRegistration to delegate to NewBrazilianVoteRegistrationCustom
with the package's default language/translation instead of calling
generateBrazilianVoteRegistration (which returns sentinel errors like
ErrInvalidCheckDigit1, ErrInvalidCheckDigit2, ErrInvalidVoteRegistration).
Replace the body of NewBrazilianVoteRegistration to call
NewBrazilianVoteRegistrationCustom(defaultLang, defaultTranslations,
otherParams...) (or whatever default constants/config you have) so all callers
receive localized error messages from the same path; alternatively, if you
prefer to keep generateBrazilianVoteRegistration, add a lang/translations
parameter to it and convert its error returns to localized messages, but the
simpler change is to have NewBrazilianVoteRegistration delegate to
NewBrazilianVoteRegistrationCustom.
In `@pkg/mocai/translations/pt_br.go`:
- Around line 65-67: Remove the dead single-value registration for
"phone_area_code" and its misleading "legacy API" comment: delete the map entry
that assigns phone_mocks.AreaCodes[rand.Intn(len(phone_mocks.AreaCodes))] to
"phone_area_code" in pt_br.go (the one intended for the legacy API), since the
codebase uses translations.GetList(lang, "phone_area_code") and there are no
calls to translations.Get("phone_area_code"); keep the plural list registration
(used by translations.GetList) intact and ensure no other references rely on the
removed single-value key.
In `@README.md`:
- Around line 92-97: The "Error Messages & Localization" paragraph is currently
inside the Go example code block (before the closing brace of main() and the
closing code fence), so cut that section out of the code block and paste it
after the example's closing code fence; ensure the example ends with the closing
'}' of main() and the triple backtick code fence before the moved documentation
so the markdown renders as normal text rather than part of the code block.
---
Nitpick comments:
In `@pkg/mocai/entities/address/generator.go`:
- Around line 68-81: Reuse the already-obtained UF map instead of calling
translations.GetUFMap(supportedLang) again (use the existing ufMap variable),
and avoid assuming address_uf list alignment with address_state: when ufMap is
nil, do not index address_uf by stateIdx; instead try to find a matching UF by
locating the state's index in the address_state list or build a map from the
address_state and address_uf lists to look up by state, and only fall back to a
random selection from address_uf if no match is found; update code that
references ufMap, uf, stateIdx, state, translations.GetUFMap and
translations.GetList accordingly.
- Around line 35-42: The code silently falls back to "ptbr" when
translations.GetUFMap(lang) == nil; change this so unsupported languages are not
silent: when GetUFMap(lang) returns nil, emit a warning (use the package logger
or returned error path) that includes the requested lang and that you're falling
back to "ptbr", and update the function doc comment to document this fallback
behavior (or alternatively change the function to return an error instead of
falling back). Ensure the check around supportedLang/GetUFMap(lang) and
subsequent calls to translations.GetList(supportedLang, "address_*") reference
the same variables (supportedLang, GetUFMap) so the warning/error is emitted
before using translations.GetList.
In `@pkg/mocai/entities/phone/generator.go`:
- Around line 32-34: The area code empty-string check is too narrow—before
selecting an areaCode, validate and trim the entire areaCodes slice (e.g.,
iterate over areaCodes and apply strings.TrimSpace, removing or rejecting empty
entries) similar to address/generator.go's upfront validation so you never pick
an empty value; update the generator function that sets areaCodes/areaCode to
perform this sanitization and only proceed if there is at least one non-empty
trimmed area code, otherwise return the same translations.Get(lang,
"error_generating_phone") error.
In `@pkg/mocai/translations/safe_rand.go`:
- Around line 11-13: The constructor NewSafeRandSource should avoid
double-wrapping an already-safe source: in NewSafeRandSource check whether the
incoming rnd is already a *SafeRandSource (type assertion) and if so return it
directly instead of creating a new wrapper; update callers like NewMocker (or
any code that passes a RandSource) to rely on this behavior so you don't nest
mutexes unnecessarily.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 353b36bf-0627-4bfa-9ec9-64b29821d370
📒 Files selected for processing (15)
README.mddocs/localization/pt/README-PT.mdpkg/mocai/entities/address/generator.gopkg/mocai/entities/certificate/countries/brazilian_certificates.gopkg/mocai/entities/company/countries/brazilian_company.gopkg/mocai/entities/cpf/generator.gopkg/mocai/entities/gender/gender.gopkg/mocai/entities/nationalid/countries/brazilian_national_id.gopkg/mocai/entities/person/generator.gopkg/mocai/entities/phone/generator.gopkg/mocai/entities/voteregistration/countries/brazilian_vote_registration.gopkg/mocai/mocker.gopkg/mocai/translations/pt_br.gopkg/mocai/translations/safe_rand.gopkg/mocai/translations/translations.go
pkg/mocai/entities/certificate/countries/brazilian_certificates.go
Outdated
Show resolved
Hide resolved
pkg/mocai/entities/voteregistration/countries/brazilian_vote_registration.go
Show resolved
Hide resolved
…sistent error handling
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
pkg/mocai/entities/certificate/countries/brazilian_certificates.go (1)
142-152:⚠️ Potential issue | 🟠 MajorBug:
langparameter not forwarded, error messages always in pt_br.The
langparameter is received but not passed togenerateCertificateCustom, causing all error messages to use the default"pt_br"locale. The comment is misleading—while certificate numbers don't depend on language, the error messages do (viatranslations.Get).The same issue exists in
generateMarriageCertificateCustom(line 156) andgenerateDeathCertificateCustom(line 167).Proposed fix
func generateBirthCertificateCustom(lang string, formatted bool, rnd translations.RandSource) (*BirthCertificate, error) { - // Note: The 'lang' parameter is currently unused because certificate numbers do not depend on language. - // It will be relevant only if textual data (e.g., names, descriptions) is added in the future. - base, err := generateCertificateCustom(rnd, formatted, brazilianBirthCertificateType) + base, err := generateCertificateCustom(rnd, formatted, brazilianBirthCertificateType, lang) if err != nil { return nil, err }Apply similarly to
generateMarriageCertificateCustomandgenerateDeathCertificateCustom.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/mocai/entities/certificate/countries/brazilian_certificates.go` around lines 142 - 152, The functions generateBirthCertificateCustom, generateMarriageCertificateCustom, and generateDeathCertificateCustom accept a lang parameter but currently do not pass it to generateCertificateCustom, causing translation lookups (translations.Get) to always use the default locale; update each function to forward the lang argument into the generateCertificateCustom call (i.e., call generateCertificateCustom(lang, rnd, formatted, brazilianBirthCertificateType) or the equivalent signature used in your codebase) so error messages use the provided locale; ensure you match the existing parameter order and types for generateCertificateCustom in all three functions.
🧹 Nitpick comments (2)
pkg/mocai/entities/certificate/countries/brazilian_certificates.go (2)
94-111: Unreachable validation branches.These negative checks can never trigger because
rnd.Intn(n)returns values in[0, n), and adding a positive offset ensures the results are always positive:
vitalRecordsOffice: always in[100000, 900000)bookNumber: always in[10000, 100000)pageNumber: always in[100, 1000)termNumber: always in[1000000, 10000000)Consider removing these unreachable branches or, if defensive checks are desired, validating against the actual expected ranges instead.
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/mocai/entities/certificate/countries/brazilian_certificates.go` around lines 94 - 111, The negative-value checks after random generation (vitalRecordsOffice, bookNumber, pageNumber, termNumber) are unreachable; remove those if you want to eliminate dead code, or replace them with meaningful range assertions matching the intended valid ranges (e.g., ensure vitalRecordsOffice is within 100000..899999, bookNumber within 10000..89999, pageNumber within 100..899, termNumber within 1000000..8999999) and use the existing translation error messages when those range checks fail; update the checks around the variables vitalRecordsOffice, bookNumber, pageNumber, and termNumber accordingly.
96-126: Remove unused sentinel errors from errors.go.The sentinel errors (
ErrInvalidCertificate,ErrInvalidVitalRecordsOffice,ErrInvalidArchive,ErrInvalidVitalRecordsService,ErrInvalidBirthYear,ErrInvalidBookNumber,ErrInvalidPageNumber,ErrInvalidTermNumber,ErrInvalidNumberWithoutCheckDigits) inpkg/mocai/entities/certificate/countries/errors.goare now dead code. They are not referenced anywhere in the codebase after the shift from wrapping errors with sentinel values to using localized error messages viatranslations.Get(). These unused definitions should be cleaned up.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@pkg/mocai/entities/certificate/countries/brazilian_certificates.go` around lines 96 - 126, Remove the now-dead sentinel error variables (ErrInvalidCertificate, ErrInvalidVitalRecordsOffice, ErrInvalidArchive, ErrInvalidVitalRecordsService, ErrInvalidBirthYear, ErrInvalidBookNumber, ErrInvalidPageNumber, ErrInvalidTermNumber, ErrInvalidNumberWithoutCheckDigits) from errors.go and any associated unused imports; update or delete comments referencing them and run a quick repo-wide search to ensure no remaining references to those symbols remain (if any are found, replace usage with the localized translations.Get(...) error strings already in use such as in the certificate generation logic that produces errors via translations.Get).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@pkg/mocai/entities/certificate/countries/brazilian_certificates.go`:
- Around line 142-152: The functions generateBirthCertificateCustom,
generateMarriageCertificateCustom, and generateDeathCertificateCustom accept a
lang parameter but currently do not pass it to generateCertificateCustom,
causing translation lookups (translations.Get) to always use the default locale;
update each function to forward the lang argument into the
generateCertificateCustom call (i.e., call generateCertificateCustom(lang, rnd,
formatted, brazilianBirthCertificateType) or the equivalent signature used in
your codebase) so error messages use the provided locale; ensure you match the
existing parameter order and types for generateCertificateCustom in all three
functions.
---
Nitpick comments:
In `@pkg/mocai/entities/certificate/countries/brazilian_certificates.go`:
- Around line 94-111: The negative-value checks after random generation
(vitalRecordsOffice, bookNumber, pageNumber, termNumber) are unreachable; remove
those if you want to eliminate dead code, or replace them with meaningful range
assertions matching the intended valid ranges (e.g., ensure vitalRecordsOffice
is within 100000..899999, bookNumber within 10000..89999, pageNumber within
100..899, termNumber within 1000000..8999999) and use the existing translation
error messages when those range checks fail; update the checks around the
variables vitalRecordsOffice, bookNumber, pageNumber, and termNumber
accordingly.
- Around line 96-126: Remove the now-dead sentinel error variables
(ErrInvalidCertificate, ErrInvalidVitalRecordsOffice, ErrInvalidArchive,
ErrInvalidVitalRecordsService, ErrInvalidBirthYear, ErrInvalidBookNumber,
ErrInvalidPageNumber, ErrInvalidTermNumber, ErrInvalidNumberWithoutCheckDigits)
from errors.go and any associated unused imports; update or delete comments
referencing them and run a quick repo-wide search to ensure no remaining
references to those symbols remain (if any are found, replace usage with the
localized translations.Get(...) error strings already in use such as in the
certificate generation logic that produces errors via translations.Get).
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 756f0f4c-6085-4d44-98f8-5dc1461f1a67
📒 Files selected for processing (1)
pkg/mocai/entities/certificate/countries/brazilian_certificates.go
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@README.md`:
- Around line 95-101: Remove the stray opening fenced code block marker (``` )
that appears after the "You do not need to perform any extra steps for error
localization — Mocai handles this automatically for all supported languages."
paragraph so the rest of README renders correctly; either delete the stray
triple-backtick or add the matching closing triple-backtick immediately after it
so the block is properly terminated.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 19d0bf7c-5e74-4c22-8dee-a06689405f05
📒 Files selected for processing (13)
README.mddocs/localization/pt/README-PT.mdpkg/mocai/entities/address/errors.gopkg/mocai/entities/certificate/countries/errors.gopkg/mocai/entities/cnpj/errors.gopkg/mocai/entities/company/countries/errors.gopkg/mocai/entities/cpf/errors.gopkg/mocai/entities/gender/errors.gopkg/mocai/entities/nationalid/countries/errors.gopkg/mocai/entities/person/errors.gopkg/mocai/entities/phone/errors.gopkg/mocai/entities/voteregistration/countries/errors.gopkg/mocai/translations/errors.go
💤 Files with no reviewable changes (9)
- pkg/mocai/entities/cnpj/errors.go
- pkg/mocai/entities/nationalid/countries/errors.go
- pkg/mocai/entities/person/errors.go
- pkg/mocai/translations/errors.go
- pkg/mocai/entities/phone/errors.go
- pkg/mocai/entities/gender/errors.go
- pkg/mocai/entities/company/countries/errors.go
- pkg/mocai/entities/certificate/countries/errors.go
- pkg/mocai/entities/cpf/errors.go
✅ Files skipped from review due to trivial changes (3)
- docs/localization/pt/README-PT.md
- pkg/mocai/entities/voteregistration/countries/errors.go
- pkg/mocai/entities/address/errors.go
There was a problem hiding this comment.
Actionable comments posted: 1
♻️ Duplicate comments (1)
README.md (1)
100-100:⚠️ Potential issue | 🟠 MajorRemove the stray fenced-code marker at Line 100.
This opens a new code block that is not closed, so the remaining README content can render incorrectly.
🛠️ Proposed fix
-```🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@README.md` at line 100, Remove the stray fenced-code marker "```" that opens an unclosed code block in README.md (the lone marker shown in the diff); delete that line so the README's remaining content renders correctly and no unintended code block remains.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@README.md`:
- Around line 72-99: Update the README "Error Messages & Localization" wording
to avoid absolute claims—change "All error messages returned by Mocai are always
localized and user-friendly" to something like "Error messages are localized
when translation keys are available; otherwise a default (English) message is
used" and note that localization depends on available translation keys for a
given Mocker instance; also either adjust the claim or ensure coverage by
aligning the address-related error messages (address error identifiers in
entities/address errors) and missing keys in the pt_br translations so the
README claim matches actual behavior for Mocker.
---
Duplicate comments:
In `@README.md`:
- Line 100: Remove the stray fenced-code marker "```" that opens an unclosed
code block in README.md (the lone marker shown in the diff); delete that line so
the README's remaining content renders correctly and no unintended code block
remains.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: f0e67578-fe6e-4057-9742-0faaaacd4e76
📒 Files selected for processing (2)
README.mddocs/localization/pt/README-PT.md
✅ Files skipped from review due to trivial changes (1)
- docs/localization/pt/README-PT.md
…tration, unify logic and comments
There was a problem hiding this comment.
Pull request overview
This PR focuses on stabilizing mock data generation by adding phone number generation, improving concurrency safety around randomness, and expanding/clarifying localized error messaging behavior in documentation.
Changes:
- Added a concurrency-safe random source wrapper and ensured
Mockeralways uses it. - Added phone area code data to translations and exposed
Mocker.NewPhone(). - Shifted multiple generators toward localized, user-facing error strings and updated README docs (EN/PT) accordingly.
Reviewed changes
Copilot reviewed 26 out of 26 changed files in this pull request and generated 8 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/mocai/translations/translations.go | Adds UF-state mapping helper and contains the translation registry APIs. |
| pkg/mocai/translations/safe_rand.go | Introduces a mutex-wrapped RandSource for concurrency safety. |
| pkg/mocai/translations/pt_br.go | Registers phone_area_code list and minor list formatting tweaks. |
| pkg/mocai/translations/errors.go | Removes a translation-level exported sentinel error. |
| pkg/mocai/mocker.go | Wraps RNG with SafeRandSource and adds NewPhone; removes GetRand. |
| pkg/mocai/entities/voteregistration/countries/errors.go | Updates vote registration error strings with clearer prefixes. |
| pkg/mocai/entities/voteregistration/countries/brazilian_vote_registration.go | Routes default constructor to localized custom generator; changes error returns. |
| pkg/mocai/entities/phone/generator.go | Implements phone generation using translated area code lists and localized errors. |
| pkg/mocai/entities/phone/errors.go | Removes exported phone sentinel errors. |
| pkg/mocai/entities/person/generator.go | Changes person generation errors to localized strings. |
| pkg/mocai/entities/person/errors.go | Removes exported person sentinel errors. |
| pkg/mocai/entities/nationalid/countries/errors.go | Removes exported national-id sentinel error. |
| pkg/mocai/entities/nationalid/countries/brazilian_national_id.go | Adjusts national ID error formatting to localized strings. |
| pkg/mocai/entities/gender/gender.go | Changes gender generation errors to localized strings. |
| pkg/mocai/entities/gender/errors.go | Removes exported gender sentinel errors. |
| pkg/mocai/entities/cpf/generator.go | Changes CPF formatting error to localized string. |
| pkg/mocai/entities/cpf/errors.go | Removes exported CPF sentinel error. |
| pkg/mocai/entities/company/countries/errors.go | Removes exported company sentinel errors. |
| pkg/mocai/entities/company/countries/brazilian_company.go | Changes company generation errors to localized strings. |
| pkg/mocai/entities/cnpj/errors.go | Removes exported CNPJ sentinel error. |
| pkg/mocai/entities/certificate/countries/errors.go | Removes exported certificate sentinel errors. |
| pkg/mocai/entities/certificate/countries/brazilian_certificates.go | Changes certificate error returns to localized strings; adds note about lang. |
| pkg/mocai/entities/address/generator.go | Pairs state/UF selection via map fallback and adjusts language fallback behavior. |
| pkg/mocai/entities/address/errors.go | Updates address error messages and removes ErrNoUFs. |
| docs/localization/pt/README-PT.md | Adds notes about localized error messages and expands localization section. |
| README.md | Adds notes about localized error messages and expands localization section. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary by CodeRabbit
New Features
Improvements
Documentation