Flows stopped as the credentials could not be decrypted

#1

NR on OS X, recently updated.

Problem: Everything was fine just a minute ago. I had a bunch of flows (some with Twitter credentials) working fine. I'm playing with a flaky USB-RS485 converter to do some Modbus and I had to stop NR. When I restarted it, It presented me with NO FLOWS whatsoever. I had seen this before as NR once decided I was not "jm" but rather "jm.local" and created a new flow file. I set the flowfile variable to be /Users/jm/.node-red/flows_jm.json to prevent that from happening. So I killed NR again and checked, no there wasn't a new flows_jm.local.json. I re-started NR and was returned to a state of flows from some time ago, very confusing. Stopped NR again. Re-started with the -s flows_jm.json and got an error about not being able to decrypt my credentials:

8 Feb 00:40:36 - [warn] Error loading credentials: SyntaxError: Unexpected token � in JSON at position 1
8 Feb 00:40:36 - [warn] Error loading flows: Error: Failed to decrypt credentials

Stopped NR and restarted without the -s and got a similar error:

8 Feb 01:01:12 - [warn] Error loading credentials: SyntaxError: Unexpected token B in JSON at position 0
8 Feb 01:01:12 - [warn] Error loading flows: Error: Failed to decrypt credentials

And now it will not load any flows:

Flows stopped as the credentials could not be decrypted.

Either way, what I was just working on is gone.

What causes that sort of behavior and how can I either recover or prevent it from happening in the future?

Thanks.

0 Likes

#2

Have you got a backup of the flows file from when it was working well? Presumably not. There is a moral there. Before you go any further I suggest you make a backup of the .node-red folder just in case the problem gets worse.

Node red will not by itself have decided to change your name. What exactly do you mean by changing your name? Did your logon name change?
Are you sure you are not logged on as a different user?
Show us what you have got in settings.js? Check in the node red log when you start node-red to see which file it is.

0 Likes

#3

@CaptClaude, clarification and clues, but no solution:

I've had that happen and solved it the same way you have. I suspect it is a quirk in how macOS handles mdns and possibly how NR gets the hostname. (I think that strictly speaking the .local part is a top-level domain name, not part of the hostname, and should be ignored by NR, but that's a topic for another day.)

Sounds like NR was using the .backup flow file, possibly because it could not find or read the current flow file.

Had you defined credentialSecret in the settings.js file or were you using the system generated key? Sounds like the key has gone bad or missing. Still, I think this should only stop you loading your credentials, not the flows. So, these are all the hints I can give you.

0 Likes

#4

Let's just say that it has been a bad couple of days for me, node-red wise. My work installation (W7) is also hosed although for a different reason.

  1. I just re-read my settings.js file and there are two things of interest:
    a) I set the flowfile:
    // The file containing the flows. If not set, it defaults to flows_.json
    flowFile: '/Users/jm/.node-red/flows_jm.json',
    b) I have a local key:
    credentialSecret: "my-super-secret-key",

  2. Backup? Yes, but it was working great one minute and not working the next. I suspect that ^C-ing out of NR caused corruption of something. But @Colin is correct about the life lesson here. Folder backed-up, errors and all. #LiveAndLearn. I'm new at this (but very old at other things).

  3. If I open my flows file in Brackets and search for the name I gave to the last thing I was working on, I can find it. But that flow does not show up when I start NR. Brackets seems to highlight json syntax in the file up to a certain point and then stops. Maybe that's a Brackets thing and it gets tired of highlighting 79kB of json. I don't know whether it's possible to recover but there were a number of flows I'd brefer not to have to recreate from scratch.


    TextWrangler does not do that highlighting difference so that might be a false positive.

  4. Flows file name changing: By default, if flowFile is not set, it defaults to flows_<hostname>.json, that's pretty well understood. I'm on OS X and before I set flowFile, I was happily flows_jm.json until one day I wasn't. My flows were gone and a new flowsFile had been created: flows_jm.local.json -- as @drmibell supposes, probably something to do with, um, something like mdns. To guard against that, I set flowFile to a known value. Fortunately, the old flowFile was still there, just being ignored.

SO: Since I have my own secret key, maybe the credentials file is hosed and I need to re-create it, probably not a huge problem. I will do that.

Is there a magic incantation that locates problems in json files that prevents flows from showing up?

Thanks,
--Jeff

0 Likes

#5

Problem Solved.
For the sake of completeness, I left my reply above. However, Trial and Error saves the day.

Brain fade: node-red -s [settings file] not flows file!

Playing with the credentials file because of the error

8 Feb 18:50:16 - [warn] Error loading credentials: SyntaxError: Unexpected token <unprintable character> in JSON at position 0
8 Feb 18:50:16 - [warn] Error loading flows: Error: Failed to decrypt credentials

prompted me to delete the credentials and re-start. All flows are back up and running except those for which credentials are required and I will now re-enter them.

Thanks for your patience.

--Jeff

0 Likes

#6

flows_jm.local.json
ahh I'll bet you had a network hiccup and it changed your computer name. Go to System Preferences -> Sharing and look at your Computer name. If you press the Edit you will see the Local host name which is what is used for .

You can edit it there if you need to.

If you use the finder and go to your user directory then select the Go tab and select Go to folder... and enter .node-red you can get into the node =-red folder.

Now press shift/Open Apple/period and it will reveal all the hidden files (pressing the keys again will hide the hidden files). You should see a backup of your flows and credentials. You could try using them to get back at least some of the way to where you were.

0 Likes

#7

I keep all my hidden files visible. I am very old school. Raised on Berkley UNIX on VAXen :sunglasses:
I move back and forth between two networks using NR, one is Apple-centric and the other is Windows-centric with a Verizon router that seems to assign strange names (not the proper ".local" :grimacing:). The missing-flows-file problem first showed up when I came home from being connected to that other network.
Since I set the flowFile=flows_jm.json I have not had problems at home or anywhere else.

Thanks for responding.

2 Likes