fix: parser correctness fixes (integer precision, nil safety, multi-variable lookup, type coercion, IfValue, XML duplicates)#179
Conversation
- UnmarshalJSON: guard against nil pointer panic on missing 'file'/'parser' keys
- LookupConfigurationValue: resolve each {{ config.x }} placeholder independently
so composite values like '{{ config.a }}:{{ config.b }}' expand correctly
- setValueWithSjson: drop implicit string→int coercion in default case to
preserve the original value type
- parseTextFile: honour if_value condition (was silently ignored before)
- parseXmlFile: remove existing attribute before CreateAttr to prevent
duplicates on repeated parses
|
Warning Rate limit exceeded
You’ve run out of usage credits. Purchase more in the billing tab. ⌛ How to resolve this issue?After the wait time has elapsed, a review can be triggered using the We recommend that you space out your commits to avoid hitting the rate limit. 🚦 How do rate limits work?CodeRabbit enforces hourly rate limits for each developer per organization. Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout. Please see our FAQ for further information. ℹ️ Review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughConfiguration file parsing enhancements add validation during unmarshalling, support multiple placeholder substitutions with graceful fallback, improve YAML numeric precision via ChangesConfiguration File Parsing and Replacement
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 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.
Pull request overview
Note
Copilot was unable to run its full agentic suite in this review.
This PR hardens the configuration file parser by adding defensive checks for required JSON keys, fixing YAML numeric handling for large integers, supporting multiple placeholder substitutions, and adding an if_value conditional for text-file replacements.
Changes:
- Safer JSON unmarshaling of
ConfigurationFilewith explicit errors for missing required keys and graceful handling of optionalreplace. - YAML parsing now uses
json.DecoderwithUseNumber()plus anormalizeYamlTypeshelper to preserve int64 precision (e.g., Snowflake IDs). LookupConfigurationValuenow replaces all placeholders, and XML attribute updates remove the existing attribute before re-creating it.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 7 comments.
| File | Description |
|---|---|
| parser/parser.go | Defensive JSON key access, YAML numeric normalization, XML attribute replace fix, and if_value support for text replacements. |
| parser/helpers.go | Removed implicit string→int coercion in sjson setter and rewrote LookupConfigurationValue to handle multiple placeholders. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Summary
This PR fixes six bugs in the configuration file parser (
parser/parser.go,parser/helpers.go).Changes
1. YAML: Preserve integer precision for large values (
parser.go)json.UnmarshalwithoutUseNumber()converts integers larger than 2⁵³ tofloat64, causing precision loss. For example, a Snowflake ID like150553673164927820would be written to disk as1.5055367316492782e+18.The TOML parser already used
UseNumber()correctly — this fix applies the same approach to the YAML parser: usejson.NewDecoderwithUseNumber()and a newnormalizeYamlTypes()function that convertsjson.Numbervalues to properint64/float64before marshalling back to YAML.2.
UnmarshalJSON: nil pointer dereference on incomplete egg config (parser.go)If a configuration file entry from the panel was missing the
fileorparserkeys, Wings would panic with a nil pointer dereference. Added explicitokchecks before dereferencing map values and return a descriptive error instead.3.
LookupConfigurationValue: only first placeholder resolved (helpers.go)When a
replace_withvalue contained multiple{{ config.x }}placeholders (e.g.{{ config.uuid }}-{{ config.port }}), only the first one was looked up and its value was substituted for all placeholders. Replaced the singleReplaceAllStringcall with a loop overFindAllStringthat resolves and substitutes each placeholder individually.4.
setValueWithSjson: string values silently coerced to integers (helpers.go)The default case in
setValueWithSjsoncalledstrconv.Atoion string values and stored the integer result if successful. This caused string values like"25565"to be written as the integer25565, changing the type of the value in config files unexpectedly. Removed the coercion — strings are now always stored as strings.5.
parseTextFile:IfValuecondition never evaluated (parser.go)The
IfValuefield on a replacement rule was never checked in the plain-text file parser. Lines were always replaced regardless of the current value. Added an explicit check: ifIfValueis set, skip the replacement unless the current value of that line matches.6.
parseXmlFile: duplicate attributes on repeated runs (parser.go)etree.CreateAttrdoes not overwrite an existing attribute — it appends a second one. On every Wings restart, XML config files would accumulate duplicate attributes. Addedelement.RemoveAttr(k)beforeelement.CreateAttr(k, v)to ensure idempotent writes.Summary by CodeRabbit
Release Notes
Bug Fixes
Refactor