Developers

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
matrixebiz
Roku Guru

Small fail-safe redundancy code change

Hello,  using the below example that provides some fail-safe redundancy if original file location no longer exists;

result = parseXmlDocument ("http://patebin.com/raw/qerberbb")
  'If there's no content, the result will be empty, so we try parsing another link
  if result.count() < 1 then result = parseXmlDocument ("http://myserver.com/xml.xml")
  if result.count() < 1 then result = parseXmlDocument ("pkg:/xml/categories.xml")
  'Error message if all links fail
  if result.count() < 1 then uiFatalError ("Channel", 40, "Unable to parse Xml document")
uiDisplay (result)


Thank you
Tags (1)
0 Kudos
7 REPLIES 7
matrixebiz
Roku Guru

Re: Small fail-safe redundancy code change

NVM - I modified the code successfully
Tags (1)
0 Kudos
RokuMarkn
Visitor

Re: Small fail-safe redundancy code change

There's no way to tell without knowing what your function getStreamId does.  If it returns an roArray, and if that roArray always contains at least one element except in the error case you are trying to detect, then your code should work.

--Mark
Tags (1)
0 Kudos
matrixebiz
Roku Guru

Re: Small fail-safe redundancy code change

NVM - I modified the code successfully
Tags (1)
0 Kudos
RokuMarkn
Visitor

Re: Small fail-safe redundancy code change

You need to post the whole function.  The important part is the return statement, but you didn't show that.

--Mark
Tags (1)
0 Kudos
matrixebiz
Roku Guru

Re: Small fail-safe redundancy code change

NVM - I modified the code successfully
Tags (1)
0 Kudos
RokuMarkn
Visitor

Re: Small fail-safe redundancy code change

Well, the last line before the return is unconditionally pushing an empty string onto the array, so the array size will never be zero even if the URL transfer fails.  I'm not completely understanding the logic, but you need to determine whether, when the URL fails, you want the array to be empty or to contain one empty string.  If the latter then you need to adjust your count test accordingly.

--Mark
Tags (1)
0 Kudos
matrixebiz
Roku Guru

Re: Small fail-safe redundancy code change

NVM - I modified the code successfully

url = "http://pastebin.com/raw/awegweg"
     If url <> ""
          url = "http://myserver.com/file.txt"
     End If
Tags (1)
0 Kudos
Community is Being Upgraded!

We’re upgrading Roku Community to bring you a faster, more mobile-friendly experience. You may notice limited functionality or read-only access during this time. Read more here.

Planned Downtime:
Community will be unavailable for up to 24–48 hours during the upgrade window during the week of May 19th and you may notice reduced functionality. In the meantime, for additional assistance, visit our Support Site.

We're sorry for this disruption — we’re excited to share what’s next!