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.

`e.failures is not iterable` when trying to access failures

See original GitHub issue

superstruct version: 0.10.11 node version: 12.17.0

I’m struggling to access failures and hoping someone here could help out…

const { object, assert, string } = require('superstruct');

const User = object({
  firstName: string(),
  lastName: string()
});

try {
  assert({}, User);
} catch (e) {
  for (const failure of e.failures) {
    console.log('failure', failure);
  }
}

Result: TypeError: e.failures is not iterable

How can I get an actual array of failures? It looks like it’s a generator of some sorts.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
ianstormtaylorcommented, Jun 20, 2020

Uhoh, sounds like a bug. Can one of you open another issue for it and I’ll check it out? Thanks!

1reaction
aegorxcommented, Jun 19, 2020

@ianstormtaylor

const User = object({
  firstName: string(),
  lastName: string()
});

try {
  assert({}, User);
} catch (e) {
  for (const failure of e.failures()) {
    console.log('failure', failure);
  }
}
// output 
 failure {
    value: undefined,
    type: 'string',
    path: [ 'firstName' ],
    branch: [ {}, undefined ]
  }
 but I want to get `firstName` and `lastName`  fields.
Read more comments on GitHub >

github_iconTop Results From Across the Web

[Bug?]: YN0001: TypeError: e is not iterable #3877 - GitHub
I had been working on trying to upgrade from Yarn 3.0.2 to 3.1.1 in another branch. The problem only happened after having worked...
Read more >
TypeError: 'Question' object is not iterable in test case assertion
FAILED (errors=1) Destroying test database for alias 'default'... In the command line: >>> from django.test.utils import setup_test_environment ...
Read more >
Demo of Python failure reports with pytest
Here is a nice run of several tens of failures and how pytest presents things ... not f() E assert not 42 E...
Read more >
How to gracefully handle failures in a Node.js API client
Intermittent failures across internet works are statistically unusual on the whole, but still bound to occur.
Read more >
Demo of Python failure reports with pytest
Here is a nice run of several failures and how pytest presents things: ... assert not f() E assert not 42 E +...
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