Skip to content
Source
Sign inSign up
TanStack/db

Live collection error status not working #1260

Send to my agent
Closedkenjiqq(GitHub profile, opens in a new tab) opened this issue 1 comment
  • I've validated the bug against the latest version of DB packages

Describe the bug Live collections are supposed to indicate when they have errored as shown in https://tanstack.com/db/latest/docs/guides/error-handling#collection-status-and-error-states But when queryFn throws errors the collection is marked as ready and no error status is activated.

To Reproduce Simply throw an error from the query function and observe the isError() signal of the live collection.

@Injectable({
  providedIn: 'root',
})
export class Transtackdb {
  queryClient = inject(QueryClient);
  todoCollection = createCollection(
    queryCollectionOptions({
      queryKey: ['todos'],
      queryClient: this.queryClient,
      queryFn: async (): Promise<Todo[]> => {
        throw new Error('Failed to fetch todos');
      },
      getKey: (item) => item.id,
    }),
  );
}
@Component({
  selector: 'app-tanstackdb',
  template: `
    <div>Status: {{ query.status() }}</div>
    <div>Loading: {{ query.isLoading() }}</div>
    <div>Ready: {{ query.isReady() }}</div>
    <div>Error: {{ query.isError() }}</div>
    <div>Total: {{ query.data().length }}</div>
    <ul>
      @for (todo of query.data(); track todo.id) {
        <li>
          {{ todo.text }}
        </li>
      }
    </ul>
  `,
})
export class Tanstackdb {
  tanstackDb = inject(Transtackdb);

  query = injectLiveQuery((q) =>
    q.from({ todo: this.tanstackDb.todoCollection }).where(({ todo }) => eq(todo.completed, false)),
  );
}

This displays: Status: ready Loading: false Ready: true Error: false Total: 0

Expected behavior Expected error to be true.

Desktop (please complete the following information):

  • OS: Mac
  • Browser Chrome "@tanstack/angular-db": "0.1.52",
  1. Found this old PR that might be related to the same issue https://github.com/TanStack/db/pull/671

  2. tannerlinsley closed this

Sign in to join this conversation.