Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't catch TypeError #2

Open
KristjanESPERANTO opened this issue Jan 14, 2023 · 3 comments
Open

Can't catch TypeError #2

KristjanESPERANTO opened this issue Jan 14, 2023 · 3 comments
Labels

Comments

@KristjanESPERANTO
Copy link
Contributor

I'm trying to catch the TypeError but I'm failing. What am I doing wrong?

This is my approach:

import json
import pyopening_hours

value = "Mo-Th 07:00-18:00, Fr 7:00-21:00 Sa 9:00-19:00"

try:
    oh = pyopening_hours.OpeningHours(value)

    if oh.getWarnings() != []:
        for line in oh.getWarnings():
            print("  " + line)
    else:
        print("no warnings")
except pyopening_hours.ParseException as error:
    print(error.message)
except json.decoder.JSONDecodeError as error:
    print(error)
except TypeError as error:
    print(error)

I get this error message:

/home/kristjan/.local/lib/python3.9/site-packages/pyopening_hours/node_modules/opening_hours/opening_hours.js:3644
                                        if (typeof tokens[nrule][0][at] === 'undefined') {
                                                                ^

TypeError: Cannot read properties of undefined (reading '0')
    at formatWarnErrorMessage (/home/kristjan/.local/lib/python3.9/site-packages/pyopening_hours/node_modules/opening_hours/opening_hours.js:3644:30)
    at getWarnings (/home/kristjan/.local/lib/python3.9/site-packages/pyopening_hours/node_modules/opening_hours/opening_hours.js:4139:20)
    at Object.getWarnings (/home/kristjan/.local/lib/python3.9/site-packages/pyopening_hours/node_modules/opening_hours/opening_hours.js:6652:11)
    at Object.prettifyValue (/home/kristjan/.local/lib/python3.9/site-packages/pyopening_hours/node_modules/opening_hours/opening_hours.js:6658:9)
    at opening_hours_object (/home/kristjan/.local/lib/python3.9/site-packages/pyopening_hours/node_modules/opening_hours/interactive_testing.js:52:18)
    at Socket.<anonymous> (/home/kristjan/.local/lib/python3.9/site-packages/pyopening_hours/node_modules/opening_hours/interactive_testing.js:69:22)
    at Socket.emit (node:events:390:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at Socket.Readable.push (node:internal/streams/readable:228:10)
Expecting value: line 1 column 1 (char 0)
@ypid
Copy link
Member

ypid commented Jan 15, 2023

TypeError is a JavaScript exception (as can be concluded from the stack trace) and not a Python exception. I mark this as a bug but I am not actively looking into it as I currently don’t use this module.

@ypid ypid added the bug label Jan 15, 2023
@KristjanESPERANTO
Copy link
Contributor Author

Ah, now I get it 💡. Thanks!

It's related to that issue: opening-hours/opening_hours.js#50, isn't it?

@ypid
Copy link
Member

ypid commented Jan 16, 2023

Looks more like the famous opening-hours/opening_hours.js#86

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants