Giter VIP home page Giter VIP logo

Comments (4)

mattt avatar mattt commented on August 18, 2024 1

Hi, @pqseags. Thanks for writing in. I'm sorry you're having trouble with this.

Here are two suggestions:

  1. The run method is a shorthand for creating a prediction and waiting for its result. It throws an error if the prediction fails. However, the longer form predictions.create method doesn't throw, and instead populates its error property. So one option would be to migrate to that method instead.

  2. The issue could be that your try-catch block isn't correctly catching promise rejections. If the run method returns a promise that rejects, and that promise rejection isn't caught inside an async function, it could be causing your catch block not to execute.

    If the code you shared is part of an async function, it should catch the error properly. But if it's not, then you'll need to declare the enclosing function as async or handle the promise with .catch():

    replicate.run(model, { input })
      .then(output => {
         console.log('after');
      })
      .catch(error => {
         console.log("catch");
      });

from replicate-javascript.

pqseags avatar pqseags commented on August 18, 2024 1

Hmm I'm not familiar enough to say for sure. Definitely odd that I was seeing inconsistent behavior as well. Either way I'm happy with the predictions.create solution - thanks for the help!

from replicate-javascript.

pqseags avatar pqseags commented on August 18, 2024

Thanks for the response @mattt. Your first suggestion worked well, and we wanted to migrate to use webhooks anyway so that's perfect.

Regarding the second suggestion however, the code is in an async function, and I ran into the same issue with .catch(). Perhaps the error is being thrown incorrectly in replicate's run method? From my understanding it should be Promise.reject() rather than throw new Error

from replicate-javascript.

mattt avatar mattt commented on August 18, 2024

@pqseags Thanks for the update. I'm glad to hear that you found a solution.

My understanding is that when an error is thrown inside an async function, it's automatically wrapped into a rejected Promise.

from replicate-javascript.

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.