Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

Error handling is primary source is absent

hi,   I would like to build a query that normally pulls the data from "C:\pathA\fileA" but if fileA is not out there, it pulls from "C:\pathB\fileB". I've tried the following but nothing works... I...
  • Smauro's avatar
    Smauro
    6 years ago

    Hi Artur,

    Your issue is with File.Contents: It gets an error trying to access the file but transforms this error into a binary anyway. So, when try is executed it gets a value but without errors, since the error is inside this value.
    Since error are transferable, I'm not sure how this happens.
    It is -- for me -- a bug of the pqengine evaluation system.

    Aaaaanyway,

    Try using file.contents alone, something like:

    Source = try (try File.Contents(filestring1))[Value]{0},
    Source_final = if Source[HasError] then File.Contents(filestring2) else File.Contents(filestring1)
    Nah, I actually tested this. It won't work since the error is still inside the binary. It happens on accessing it. This will work:

    Source = try Binary.Length((try File.Contents(filestring1))[Value])

    Source_final = if Source[HasError] then File.Contents(filestring2) else File.Contents(filestring1)

     


    And then apply the csv transformations


    Edit2: You could also simplify step1 as :
    try Binary.Length(File.Contents(filestring1))