chore: order alphabetical error codes and constants in reference#569
Conversation
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #569 +/- ##
==========================================
- Coverage 71.66% 71.65% -0.01%
==========================================
Files 226 226
Lines 19148 19154 +6
==========================================
+ Hits 13722 13725 +3
- Misses 4217 4218 +1
- Partials 1209 1211 +2 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
The ErrorCodeMap is a Go map, so iteration order was random — the generated errors.md output was non-deterministic. Sort entries by their Code field before rendering the template. Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
Co-Authored-By: Claude <svc-devxp-claude@slack-corp.com>
| errors := make([]slackerror.Error, 0, len(slackerror.ErrorCodeMap)) | ||
| for _, e := range slackerror.ErrorCodeMap { | ||
| errors = append(errors, e) | ||
| } | ||
| slices.SortFunc(errors, func(a, b slackerror.Error) int { | ||
| return strings.Compare(a.Code, b.Code) | ||
| }) | ||
| err = tmpl.Execute(file, errors) |
There was a problem hiding this comment.
If the errors are already sorted do we need this? Or are go Maps unordered?
There was a problem hiding this comment.
@WilliamBergamin I understand maps don't have a specified order so want to build confidence in these outputs 📠 But I do realize this doesn't change our actual pages...
💡 thought: Will sit on this a bit before merging because it's additional code to maintain-
|
@WilliamBergamin I slept on this a bit and will go ahead with merging now to make it more explicit what we expect in outputs! Thank you for reviewing 🎁 ✨ |
Changelog
N/A — no change to behavior but docs of #553 might keep new order 👁️🗨️ 📚
Summary
This pull request sorts the
internal/slackerror/errors.gofile alphabetically and ensuresdocgenproduces deterministic output.ErrXxxidentifier nameErrorCodeMapentries sorted by map keydocgennow explicitly sorts errors before rendering the templatePreview
Testing
diffof this PR has matching additions 🔬Notes
The Go spec states (ref):
Without explicit sorting,
docgenoutput depends on undefined map iteration order, which can vary across Go versions and builds.Requirements