Skip to content

Conversation

@KristjanESPERANTO
Copy link
Member

While investigating issue #548, I noticed that there are unnecessary outputs.

The formatWarnErrorMessage function had a syntax error (} { instead of } else {) and duplicate console output.

To be clear: This PR doesn't fix #548.

Before

$ node test.mjs
An error occurred during evaluation of the value "Mo-We 09:00-17:00; Th 07:00-21:00; Fr 07:00-(sunset-1); Sa off; Su 09:00-16:30". Please file a bug report or pull request: https://github.com/opening-hours/opening_hours.js. Bug in warning generation code which could not determine the exact position of the warning or error in value.
Last token for rule: [[[5,"weekday",43,"weekday"],[7,"number",40,"time"],[":","timesep",38],[0,"number",37],["-","-",35],["(","(",34],["sunset","timevar",33],["-","-",27],[1,"number",26],[")",")",25]],false,24]
Mo-We 09:00-17:00; Th 07:00-21:00; Fr 07:00-(sunset-1) <--- (Calculation with variable time is not in the right syntax (time).)


tokens_to_use[nrule][2] is undefined. This is ok if nrule is the last rule.
Mo-We 09:00-17:00; Th 07:00-21:00; Fr 07:00-(sunset-1) <--- (Calculation with variable time is not in the right syntax (time).)

This PR removes the last two lines. In my understanding the line before the last one should not be printed at all for this, and the last one is redundant.

After

$ node test.mjs
An error occurred during evaluation of the value "Mo-We 09:00-17:00; Th 07:00-21:00; Fr 07:00-(sunset-1); Sa off; Su 09:00-16:30". Please file a bug report or pull request: https://github.com/opening-hours/opening_hours.js. Bug in warning generation code which could not determine the exact position of the warning or error in value.
Last token for rule: [[[5,"weekday",43,"weekday"],[7,"number",40,"time"],[":","timesep",38],[0,"number",37],["-","-",35],["(","(",34],["sunset","timevar",33],["-","-",27],[1,"number",26],[")",")",25]],false,24]
Mo-We 09:00-17:00; Th 07:00-21:00; Fr 07:00-(sunset-1) <--- (Calculation with variable time is not in the right syntax (time).)

Testscript

import opening_hours from 'opening_hours';

try {
  new opening_hours('Mo-We 09:00-17:00; Th 07:00-21:00; Fr 07:00-(sunset-1); Sa off; Su 09:00-16:30')
} catch (e) {
  console.error(e);
}

Copy link
Member

@ypid ypid left a comment

Choose a reason for hiding this comment

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

This PR doesn't fix #548.

I would say you fixed it.

@KristjanESPERANTO KristjanESPERANTO merged commit 59ffe43 into opening-hours:develop Jan 18, 2026
5 checks passed
@KristjanESPERANTO KristjanESPERANTO deleted the warnerrormessage branch January 18, 2026 10:21
@KristjanESPERANTO
Copy link
Member Author

KristjanESPERANTO commented Jan 18, 2026

Yes, the third commit (which makes the fix) wasn't actually intended for this PR, as it went a bit beyond the scope of this PR. But let's leave it as it is, it's a good commit. And I'll try to be a bit more attentive in future.

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.

Bug in warning generation code which could not determine the exact position of the warning or error in value

2 participants