Giter VIP home page Giter VIP logo

Comments (2)

karlicoss avatar karlicoss commented on September 18, 2024

IMO the issue not even in logging ImportError (although this does help a bit), but because the error handling isn't robust enough.
There are actually multiple issues here at the same time:

ntfy/ntfy/__init__.py

Lines 41 to 50 in 698333c

try:
notifier = import_module('ntfy.backends.{}'.format(backend))
except ImportError:
try:
notifier = import_module(backend)
except ImportError:
logging.getLogger(__name__).error(
'Invalid backend {}'.format(backend))
ret = 1
continue

  • the first import fails due to the MAX_MESSAGE_LENGTH issue
    ImportError: cannot import name 'MAX_MESSAGE_LENGTH' from 'telegram.constants'

  • since ImportError is very broad (it doesn't check that the name of the module in exception is ntry.backedns.telegram), it tries to handle the error

    imo .args or .name for the exception object should be checked first, and if it's unrelated to the backend itself, it should be simply rethrown so it's clear what's the actual error.

  • then for some reason the code tries to import the backend as telegram

    not sure what the idea here, in case you wrote a backend and don't want it under ntfy.backends.* namespace?

  • which actually works because telegram is a library which accesses telegram API, but not a notify backend

    imo here right after importing we should check if the module we imported contains .notify function. If not, it's not a ntfy backend and the original Exception should be rethrown (again so there is less indirection and easier to understand what actually failed)

from ntfy.

karlicoss avatar karlicoss commented on September 18, 2024

Overall, even if you hack around the issue above with MAX_MESSAGE_LENGTH, sending messages to telegram still doesn't work and telegram_send library seems abandoned. So likely we need to switch to something else :( rahiel/telegram-send#121

from ntfy.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.