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

Improve FileNotFound exception #1941

Closed

Conversation

tomaszdrozdz
Copy link
Contributor

@tomaszdrozdz tomaszdrozdz commented Sep 30, 2020

@ahopkins @myusko

Without this changes my web browser shows only

File not found

With this changes it shows:

File not found: path=./some/thing relative_url=/something

@ahopkins
Copy link
Member

I think this might be an instance where it is better to leave it. If a message like that is desired, then there should probably be something to catch and reraise. We do not want to add something that could potentially leak information not intended.

@tomaszdrozdz
Copy link
Contributor Author

OK.
How about another idea ?

@ahopkins
Copy link
Member

ahopkins commented Oct 1, 2020

@app.exception(FileNotFound)
def handle_missing_files(request, exception):
    message = f"No file found at {exception.path=} looking at {exception.relative_url=}"
    return text(message, status=exception.status_code)

@ahopkins ahopkins closed this Oct 1, 2020
@tomaszdrozdz
Copy link
Contributor Author

tomaszdrozdz commented Oct 1, 2020

OK - You are right - now I understand :)


And now I understand i should have describe my issue more precisselly.

So i wanted to:

app.static("/css", "./css", "css")

But going to web browser under: /css/main.css showed me only

File not found

There was also no any information what file, what path, ... even in terminal (in command line).

(My fault, I provided wrong directory path name).

So I just thought it would help me (and I think in such case it could also help other developers writing Sanic app) if I had more detailed information in terminal (command line) where I run my Sanic app in debug mode, about what is not found.

Hope You understand my concern that in this case (and when running Sanic in debug mode) we could be more verbose and give more hint what is wrong so it is easier to debug.

@ahopkins
Copy link
Member

ahopkins commented Oct 1, 2020

Perhaps a log.error here would help that.

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.

2 participants