Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

What's the correct way to handle missing data? #46

Closed
reimund opened this issue Sep 30, 2015 · 4 comments
Closed

What's the correct way to handle missing data? #46

reimund opened this issue Sep 30, 2015 · 4 comments

Comments

@reimund
Copy link

reimund commented Sep 30, 2015

Whenever one of my find-commands fails and gives me "(find) no results for ____" Osmosis seems to abort the chain.

I tried catching the error with .error, but my subsequent find/data commands are still ignored.

What's the correct way to make Osmosis continue, ignoring the missing data?

I'm doing something like:

osmosis
    .get(url) 
    .find(...)
        .set(...)
    .follow(...)
        .find(...)
            .set(...)
        .find(...) // This selector does not always resolve
            .set(...})
        .find(...) // This doesn't seem to run if the above fails
            .set(...)
    .follow('a@href') // Neither does this
        .find(...)
            .set(..)
    .data(function(stuff) {
        // And I never get here :(
    })
    .done(function() {
        // But I do get here...
    })
@reimund
Copy link
Author

reimund commented Oct 2, 2015

Seems like calling next in a then block after the failing set does the trick.

Eg:

osmosis
    .get(url) 
    .find(...)
        .set(...)
    .follow(...)
        .find(...)
            .set(...)
        .find(...) // This selector does not always resolve
            .set(...})
        .then(context, data, next) {
            next(context, data);
        }
        .find(...)
            .set(...)
    .follow('a@href')
        .find(...)
            .set(..)
    .data(function(stuff) {
        ...
    })
    .done(function() {
        ..
    })

@rchipka
Copy link
Owner

rchipka commented Oct 2, 2015

There isn't an official way to handle missing data. By default, Osmosis assumes that if one link in the chain fails, any subsequent commands will fail. This obviously isn't always the case. I'll be working on a solution to this.

@rchipka
Copy link
Owner

rchipka commented Oct 28, 2015

The next version of Osmosis is planned to have .do(). This command will allow one or more nested instances to run from the current context and return to the next command regardless of whether any of the nested instances failed.

osmosis.get(url)
...
.do(
    osmosis... ,
    osmosis... ,
    osmosis...
)
...

@rchipka
Copy link
Owner

rchipka commented Nov 24, 2015

Supported in 0.1.0

@rchipka rchipka closed this as completed Nov 24, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants