question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Returning an error from data.src triggers exception

See original GitHub issue

In the official codepen playground and other places you have this code now:

src: async () => {
      try {
        return data;
      } catch (error) {
        return error;
      }
}

But if this errors, autoComplete.js triggers an exception:

19:08:26.990 Uncaught (in promise) TypeError: data.store.forEach is not a function
    findMatches dataController.js:36
    default index.f58c4ea9.js:22807
    run eventController.js:27
    timer io.js:89
    setTimeout handler*debounce/< io.js:89
    input eventController.js:41
    addEvents eventController.js:71
    eventsManager eventController.js:14
    addEvents eventController.js:70
    default index.f58c4ea9.js:22471
    autoComplete autoComplete.js:37
    init index.f58c4ea9.js:1261

Because in start.js or findMatches you never validate that it didn’t error.

Also on a sidenote, I don’t think cache is working at the moment (though I believe the cache should be removed anyway), because you never set data.cache anywhere:

$ pwd
/home/folk/.../node_modules/@tarekraafat/autocomplete.js/src
$ rg '.cache'
services/init.js
48:  if (data.cache) await getData(ctx);

controllers/dataController.js
12:  if (data.cache && data.store) return;

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
folknorcommented, Jun 1, 2021

Also https://github.com/TarekRaafat/autoComplete.js/blob/7e1930626ae8cc9a8ac90fd3aac4fdf31202866b/src/autoComplete.js#L38 is wrong. I had not tried it when I wrote that, it should say something like “Makes the Tab key select the entry navigated to using the keyboard, just like Enter.”

config.data.filter should perhaps say “Used to filter and sort matching returns from config.data.src before showing them to the user. Signature: (Array), is given all the results from config.data.src that matches the query.”

0reactions
folknorcommented, Jun 2, 2021

I think I misunderstand your last comment. I’m not really able to parse and understand what you said 😛

Anyway it could be as simple as changing start.js from

    // Check if data fetch failed
    if (ctx.feedback instanceof Error) return;
    // Find matching results to the query
    findMatches(queryVal, ctx);
    // Render "resultsList"
    if (resultsList) render(ctx);

to

    if (ctx.feedback instanceof Error) {
      if (resultsList && resultsList.element && resultsList.showError) {
        ctx.cursor = -1;
        ctx.list.innerHTML = "";
        resultsList.element(ctx.list, feedback);
        open(ctx);
      }
    } else {
      // Find matching results to the query
      findMatches(queryVal, ctx);
      // Render "resultsList"
      if (resultsList) render(ctx);
    }

I realise it looks dirty. Also I’ve not tested it, and start.js needs to import open from listController. And if I was going to implement it “properly” I’d move this logic to listController, probably adding a reset function there for resetting .cursor and .innerHTML and so forth.

Anyway again I don’t really understand your previous comment so if this comment is useless please excuse me. I do understand that the error is in feedback and data.store, but not the sentence before that - this one:

Frankly, that’s how I was planning to handle errors because if it’s going to be limited to the list, then in case you’re not using the default rendered list for some reason you won’t be able to catch them and use them.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Errors function in Power Apps - Power Platform
Errors can happen when a record of a data source is changed. Many causes are possible, including network outages, inadequate permissions, ...
Read more >
jQuery Ajax error handling, show custom exception ...
Custom exception ModelStateException that gets thrown when validation fails on the server (model state reports validation errors when we use data annotations ...
Read more >
8. Errors and Exceptions — Python 3.11.1 documentation
When an exception is created in order to be raised, it is usually initialized with information that describes the error that has occurred....
Read more >
Error handling and automatic retries in AWS Lambda
When you invoke a function, two types of error can occur. Invocation errors occur when the invocation request is rejected before your function...
Read more >
Exceptions and debugging - Advanced R. - Hadley Wickham
This reruns the command that created the error, pausing execution where the error occurred. You're now in an interactive state inside the function,...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found