Skip to content

Commit

Permalink
More flux->instFlux backwards compatibility in slot setup.
Browse files Browse the repository at this point in the history
  • Loading branch information
TallJimbo committed Oct 3, 2018
1 parent 4614000 commit fbb7a03
Showing 1 changed file with 31 additions and 7 deletions.
38 changes: 31 additions & 7 deletions src/table/slots.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,42 @@ void FluxSlotDefinition::setKeys(std::string const &alias, Schema const &schema)
_measKey = MeasKey();
_errKey = ErrKey();
_flagKey = Key<Flag>();
MeasFieldNameGetter helper(s["instFlux"], schema);
if (!helper.defined) {
return;
}
_measKey = helper.replaced;

// Helper function to set _measKey and _errKey.
// Returns false if this slot isn't defined.
auto setMeasAndErr = [&](std::string const & suffix) -> bool {
MeasFieldNameGetter helper(s[suffix], schema);
if (!helper.defined) {
return false;
}
_measKey = helper.replaced;
try {
_errKey = s[suffix + "Err"];
} catch (pex::exceptions::NotFoundError &) {
// not having an err key is not an error
}
return true;
};

try {
_errKey = s["instFluxErr"];
} catch (pex::exceptions::NotFoundError &) {
if (!setMeasAndErr("instFlux")) {
return;
}
} catch (pex::exceptions::NotFoundError & err) {
// Alias was defined, but the field it targets doesn't exist.
// Before we assume the caller made a mistake and propagate the
// exception up, let's see if a field ending in "flux" rather
// than "instFlux" exists, for backwards compatibility.
try {
setMeasAndErr("flux");
} catch (pex::exceptions::NotFoundError &) {
throw err; // rethrow the outer error for a better message
}
}
try {
_flagKey = s["flag"];
} catch (pex::exceptions::NotFoundError &) {
// not having a flag key is not an error
}
}

Expand Down

0 comments on commit fbb7a03

Please sign in to comment.