Repository navigation
refactor(utils): simplify configuration validation and error handling - #4240
Conversation
4fe7ca6 to
bd1b3b3
Compare
have we a rule for this? I’ve always avoided the "function" style because I thought the "=>" syntax was the more modern one. If I search the source code (prior to this PR) for I can go ahead and merge this as is, but wouldn't it be worth settling on a single variant globally? |
|
The arrow style insures the context is set correctly, particularly on callbacks. ( timeout or interval), |
No, we don't. I'll look into which ESLint rules could help us achieve more consistency here.
Yeah, it is more modern, but I find it a bit less intuitive. Maybe it's just time for me to get used to it 😅
The numbers, together with both of your preferences, are enough for me to stick with arrow functions. I’ll update the PR accordingly 🙂 Thanks for the feedback! |
bd1b3b3 to
5a9e37e
Compare
In #4240 we discussed function declarations vs. arrow functions, and the consensus was to lean towards arrow functions. This is a follow-up to that: I enabled the ESLint rule `prefer-arrow-callback`. All found issues in the affected files were fixed automatically by ESLint itself, no manual changes needed. **Outcome:** This makes the code more consistent.
## Release Notes Thanks to: @ago1776, @alkank, @Antra, @Blackspirits, @deBasMan21, @flightlesstux, @i-xul, @jamalkamaladdin, @khassel, @KristjanESPERANTO, @MannXo, @pascalpfammatter, @rejas >⚠️ This release needs nodejs version >=22.22.2 <23 || >=24 [Compare to previous Release v2.37.0](v2.37.0...develop) ### [core] - Prepare Release 2.38.0 (#4285) - fix: let Electron select the Wayland display (#4268) - fix(http): improve access error messages (#4281) - fix: always redact client configuration (#4275) - refactor: migrate browser scripts to ESM (#4272) - refactor: convert animateCSS to ES module (#4266) - use filter instead of find to get all allowed secrets when multiple instances of a module are active (#4265) - refactor: convert notificationFx to ES module (#4263) - refactor: enforce function expression style (#4262) - fix: validate client IP behind trusted proxies (#4261) - prefer arrow over function (#4252) - refactor(utils): simplify configuration validation and error handling (#4240) - fix(server): validate request origins (#4234) - remove codeql warning (#4231) - refactor(socket): use direct ESM import in main (#4225) - refactor(socket): load Socket.IO client via ESM (#4224) - style: simplify Electron startup checks (#4213) - refactor: consolidate electron bootstrap into async function (#4210) - refactor(module): simplify and fix configMerge (#4203) - refactor: convert Translator to ES module (#4202) - docs: add CodeQL review steps and restructure after-release checklist (#4200) - refactor: centralize server port resolution (#4198) - refactor: use const instead of let for variable declarations (#4196) - refactor: replace Loader object with named exports (#4195) - set next release dev number - refactor(eslint): enforce prefer-arrow-callback rule (#4251) - refactor(http_fetcher): make dynamic URL handling explicit (#4282) - refactor: use explicit global config (#4233) - expand logic of hideConfigSecrets, add more tests (#4229) - refactor: make browser startup more explicit (#4214) ### [dependencies] - update dependencies (#4276) - update dependencies incl. electron to v44 (#4250) - chore: update eslint incl. plugins + review rules (#4236) - Bump actions/stale from 10 to 11 (#4215) - update dependencies (#4221) - Bump actions/setup-node from 6 to 7 (#4204) - chore: update dependencies (#4201) - Bump electron from 42.5.2 to 43.0.0 (#4192) ### [modules/alert] - Move alert translations into common translations (#4284) ### [modules/calendar] - Fixes issue 4243: Ensure while loop in calendar module does not get stuck when no entries (#4244) - fix(calendar): escape HTML in event title and location (#4260) - calendar: allow custom events to override symbol class (#4257) - Fix calendar crash when yearmatchgroup regex does not match (#4239) - fix(calendar): keep yearly events in DTSTART's month when BYMONTH is missing (#4222) - fix(calendar): correct multi-day slice day counts (#4232) - chore: update dependencies + adapt calendar tests (#4211) - fix(calendar): sliced multi-day events start at 00:00, not 23:59 (#4208) ### [modules/newsfeed] - newsfeed: don't use cors url in njk template (#4279) - refactor(newsfeed): extract feed item normalization into feeditem.js (#4271) - refactor(newsfeed): replace feedme lib with feedparser (#4269) - newsfeed: fix allowedBasicHtmlTags (#4258) - newsfeed: update checkArticleUrl (#4256) ### [modules/updatenotification] - feat(updatenotification): implement trusted module configuration for update commands (#4259) ### [modules/weather] - feat: add FMI weather provider (#4278) - feat(weather): enable CSS ordering for forecast and hourly columns (#4118) - fix(weather): respect initial load delay (#4254) - fix(weather): restrict provider loading to the providers directory (#4235) - refactor(weather): extract WeatherProvider base class (#4228) ### [testing] - ci: fail lint on warnings (#4230) - add test if install works for minimal node version (#4197) ### [translation] - feat(i18n): add Azerbaijani translation (#4283) - feat(i18n): complete Turkish translations (#4277) - Improve Portuguese translations (#4274) --------- Signed-off-by: dependabot[bot] <[email protected]> Co-authored-by: Kevin G. <[email protected]> Co-authored-by: veeck <[email protected]> Co-authored-by: Veeck <[email protected]> Co-authored-by: Karsten Hassel <[email protected]> Co-authored-by: Jboucly <[email protected]> Co-authored-by: Jboucly <[email protected]> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Jarno <[email protected]> Co-authored-by: sam detweiler <[email protected]> Co-authored-by: Jordan Welch <[email protected]> Co-authored-by: Blackspirits <[email protected]> Co-authored-by: Samed Ozdemir <[email protected]> Co-authored-by: in-voker <[email protected]> Co-authored-by: Andrés Vanegas Jiménez <[email protected]> Co-authored-by: cgillinger <[email protected]> Co-authored-by: Sonny B <[email protected]> Co-authored-by: sonnyb9 <[email protected]> Co-authored-by: Morgan McBee <[email protected]> Co-authored-by: Claude Opus 4.8 <[email protected]> Co-authored-by: Mike Bishop <[email protected]> Co-authored-by: ago1776 <[email protected]> Co-authored-by: pascalpfammatter <[email protected]> Co-authored-by: Pascal Pfammatter <[email protected]> Co-authored-by: Anders Demant van der Weide <[email protected]> Co-authored-by: Bas Buijsen <[email protected]> Co-authored-by: Parman Mohammadalizadeh <[email protected]> Co-authored-by: alkank <[email protected]> Co-authored-by: Henkka <[email protected]> Co-authored-by: Ercan Ermis <[email protected]> Co-authored-by: Jamal Kamaladdinoglu <[email protected]>
I ended up going down a bit of a rabbit hole with this PR. The main goal throughout was to make the code easier to understand and maintain. There are no intended changes to the normal application behavior. The error handling is also more consistent now, with error messages being passed to the point where they are handled instead of being logged in multiple places.
Please let me know if the PR has grown too large or if I have taken things in a direction that would be worth discussing 🙂
Commit 1
I started by looking at
checkConfigFileand felt that it was doing too many different things. I split its responsibilities into a few smaller functions to make the overall flow easier to follow.Outcome: clearer responsibilities and a simpler configuration validation flow.
Commit 2 (edited)
After your review comment, I decided to undo the arrow-function replacement but keep the documentation improvements instead.
Outcome: clearer JSDoc documentation while keeping the existing function style consistent with the rest of the project.
Commit 3
Finally, I noticed that some validation paths were throwing errors without any message:
An error without a message is not very helpful for debugging. This led me to move the error logging to the places where the errors are handled and to make sure that every
ConfigErrorcarries a useful message.Outcome: more consistent error handling and cleaner error output.
Commit 4
After looking at the remaining usages, I noticed that
getAvailableModulePositionswas only a thin wrapper around the internalmodulePositionsarray. It's not part of the documented API for third-party modules, so I removed it and letmoduleHasValidPositionusegetModulePositionsdirectly.Outcome: less indirection and a smaller internal API, without changing the intended behavior.