Skip to content

[Feature/53] :: fix critical data gen#54

Merged
wellfernandes merged 31 commits intodevelopfrom
feature/53-fix-critical-data-gen
Mar 22, 2026
Merged

[Feature/53] :: fix critical data gen#54
wellfernandes merged 31 commits intodevelopfrom
feature/53-fix-critical-data-gen

Conversation

@wellfernandes
Copy link
Copy Markdown
Member

@wellfernandes wellfernandes commented Mar 22, 2026

  • fixed errors in data generation
  • updated main readme
  • update ptbr readme
  • other important adjustments were made

Summary by CodeRabbit

  • New Features

    • Phone number generation added to mock data.
  • Improvements

    • Safer concurrent randomization for multi-threaded use.
    • More tolerant Brazilian address/state selection with graceful fallbacks.
    • Error handling now returns localized, user-facing messages when translations exist.
  • Documentation

    • README (EN/PT) updated with usage notes and an "Error Messages & Localization" section.

@wellfernandes wellfernandes self-assigned this Mar 22, 2026
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 22, 2026

Note

Reviews paused

It 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 reviews.auto_review.auto_pause_after_reviewed_commits setting.

Use the following commands to manage reviews:

  • @coderabbitai resume to resume automatic reviews.
  • @coderabbitai review to trigger a single review.

Use the checkboxes below for quick actions:

  • ▶️ Resume reviews
  • 🔍 Trigger review
📝 Walkthrough

Walkthrough

Refactors 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

Cohort / File(s) Summary
Documentation & Localization
README.md, docs/localization/pt/README-PT.md
Added inline error-localization comments in Go examples and a new section explaining that error messages are presented in the Mocker instance's configured language when translations exist.
Sentinel error removals & generator error changes
pkg/mocai/entities/.../errors.go (deleted files), pkg/mocai/entities/certificate/countries/brazilian_certificates.go, pkg/mocai/entities/company/countries/brazilian_company.go, pkg/mocai/entities/cpf/generator.go, pkg/mocai/entities/gender/gender.go, pkg/mocai/entities/nationalid/countries/brazilian_national_id.go, pkg/mocai/entities/person/generator.go, pkg/mocai/entities/phone/generator.go, pkg/mocai/entities/voteregistration/countries/brazilian_vote_registration.go
Removed many package-level sentinel error variables and replaced wrapped errors with plain localized error messages (fmt.Errorf("%s", ...)), changing error identity (affects callers using errors.Is/As).
Address generator & UF mapping
pkg/mocai/entities/address/generator.go, pkg/mocai/translations/translations.go
Added GetUFMap(lang) and made address generation use a UF map (ptbr) when available; pairs state→UF with fallbacks and relaxes UF presence validation.
Phone integration & pt-br lists
pkg/mocai/entities/phone/generator.go, pkg/mocai/translations/pt_br.go
Registered phone_area_code in ptbr lists; added phone generator and moved area-code sourcing to list registration; removed certain validations and sentinel wrapping in phone generation.
Mocker API & concurrent rand handling
pkg/mocai/mocker.go, pkg/mocai/translations/safe_rand.go
Added Mocker.NewPhone(), introduced SafeRandSource (mutex-wrapped RandSource) and wrapped default/provided rnd with it; removed public Mocker.GetRand().
Error-message text tweaks
pkg/mocai/entities/address/errors.go, pkg/mocai/entities/voteregistration/countries/errors.go
Adjusted text/prefixes for several retained exported error variables; many per-package error files were removed entirely.

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
Loading
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)
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~22 minutes

Possibly related PRs

Suggested labels

enhancement

Suggested reviewers

  • rluders
  • DODOSUBI
  • BruggerPedro

Poem

🐇 I nibble through the code with care,

Errors now speak the language fair,
A mutex keeps each random hop safe,
Phones and UFs find their rightful place,
The Mocker hums — localized and spare.

🚥 Pre-merge checks | ✅ 1 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 37.50% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title '[Feature/53] :: fix critical data gen' is vague and generic, using non-descriptive terms like 'fix' and 'critical data gen' without clearly conveying what specific changes were made. Provide a more specific title that clearly describes the main changes, such as 'Refactor error handling to use localized messages instead of sentinel errors' or 'Add phone number generation and improve address/data generation'.
✅ Passed checks (1 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feature/53-fix-critical-data-gen

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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown

@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: 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 *SafeRandSource to NewMocker, 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 to address/generator.go lines 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: Redundant GetUFMap call and index alignment assumption.

Two observations:

  1. GetUFMap(supportedLang) is called twice (line 36 and 68). Consider reusing the result from line 36.

  2. Line 74-75 assumes the address_uf list is index-aligned with the address_state list. 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) returns nil (currently all languages except "ptbr"), the function silently falls back to Brazilian Portuguese data. This means a caller requesting lang="en" would receive Brazilian addresses without any indication that their requested language wasn't supported.

Consider either:

  1. Returning an error for unsupported languages
  2. Logging a warning when fallback occurs
  3. 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

📥 Commits

Reviewing files that changed from the base of the PR and between d2bc7b9 and 60d8ba7.

📒 Files selected for processing (15)
  • README.md
  • docs/localization/pt/README-PT.md
  • pkg/mocai/entities/address/generator.go
  • pkg/mocai/entities/certificate/countries/brazilian_certificates.go
  • pkg/mocai/entities/company/countries/brazilian_company.go
  • pkg/mocai/entities/cpf/generator.go
  • pkg/mocai/entities/gender/gender.go
  • pkg/mocai/entities/nationalid/countries/brazilian_national_id.go
  • pkg/mocai/entities/person/generator.go
  • pkg/mocai/entities/phone/generator.go
  • pkg/mocai/entities/voteregistration/countries/brazilian_vote_registration.go
  • pkg/mocai/mocker.go
  • pkg/mocai/translations/pt_br.go
  • pkg/mocai/translations/safe_rand.go
  • pkg/mocai/translations/translations.go

Copy link
Copy Markdown

@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.

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 | 🟠 Major

Bug: lang parameter not forwarded, error messages always in pt_br.

The lang parameter is received but not passed to generateCertificateCustom, 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 (via translations.Get).

The same issue exists in generateMarriageCertificateCustom (line 156) and generateDeathCertificateCustom (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 generateMarriageCertificateCustom and generateDeathCertificateCustom.

🤖 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) in pkg/mocai/entities/certificate/countries/errors.go are 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 via translations.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

📥 Commits

Reviewing files that changed from the base of the PR and between 60d8ba7 and d8a1735.

📒 Files selected for processing (1)
  • pkg/mocai/entities/certificate/countries/brazilian_certificates.go

Copy link
Copy Markdown

@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: 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

📥 Commits

Reviewing files that changed from the base of the PR and between d8a1735 and 1c9892c.

📒 Files selected for processing (13)
  • README.md
  • docs/localization/pt/README-PT.md
  • pkg/mocai/entities/address/errors.go
  • pkg/mocai/entities/certificate/countries/errors.go
  • pkg/mocai/entities/cnpj/errors.go
  • pkg/mocai/entities/company/countries/errors.go
  • pkg/mocai/entities/cpf/errors.go
  • pkg/mocai/entities/gender/errors.go
  • pkg/mocai/entities/nationalid/countries/errors.go
  • pkg/mocai/entities/person/errors.go
  • pkg/mocai/entities/phone/errors.go
  • pkg/mocai/entities/voteregistration/countries/errors.go
  • pkg/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

Copy link
Copy Markdown

@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: 1

♻️ Duplicate comments (1)
README.md (1)

100-100: ⚠️ Potential issue | 🟠 Major

Remove 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

📥 Commits

Reviewing files that changed from the base of the PR and between 1c9892c and 642963a.

📒 Files selected for processing (2)
  • README.md
  • docs/localization/pt/README-PT.md
✅ Files skipped from review due to trivial changes (1)
  • docs/localization/pt/README-PT.md

@wellfernandes wellfernandes requested a review from Copilot March 22, 2026 17:18
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 Mocker always 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.

@wellfernandes wellfernandes merged commit 65f9e9a into develop Mar 22, 2026
2 checks passed
@wellfernandes wellfernandes deleted the feature/53-fix-critical-data-gen branch March 22, 2026 22:14
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.

3 participants