Skip to content

Instantly share code, notes, and snippets.

@mayakerostasia
Last active July 11, 2025 17:00
Show Gist options
  • Save mayakerostasia/a733eda781e147bcbbac2f1ebb26ac55 to your computer and use it in GitHub Desktop.
Save mayakerostasia/a733eda781e147bcbbac2f1ebb26ac55 to your computer and use it in GitHub Desktop.
OED: Error: 'Password should be a string' when running 'npm start testData'

Sure!
I'm going to try to debug this specific error and tell you how I'm trying to figure it out, so let me first figure out where this missing password might be\

docker compose config  

will "render" the compose file it's pointing at, so I'm going to try that and check any environment variables

I find this line... so this /might/ be it but I also kinda doubt it unless they have password length / character rules

POSTGRES_PASSWORD: pleaseChange  

this one, interesting, but we'll keep looking

OED_DB_PASSWORD: opened  

secret is another name for password so this becomres interesting

OED_TOKEN_SECRET: '?'  

maybe even this one

OED_MAIL_CREDENTIAL: credential  

also, these are all contained within the "environment" directive of the compose spec which is where I'd expect them to be
side note, docker compose has an env-file directive which sources environment variables ( set INSIDE the container ) from a file, I don't see that directive here, so we don't have to worry about that
let's do a little more digging
let's try to find out where the error comes from
now time to use a cool trick ripgrep ( it's just a rust version of grep so it's really fast! )
going to just post a few tries here so you can hopefully see my thought process

 OED  rg  
error: The following required arguments were not provided:  
    <PATTERN>  
  
USAGE:  
  
    rg [OPTIONS] PATTERN [PATH ...]  
    rg [OPTIONS] -e PATTERN ... [PATH ...]  
    rg [OPTIONS] -f PATTERNFILE ... [PATH ...]  
    rg [OPTIONS] --files [PATH ...]  
    rg [OPTIONS] --type-list  
    command | rg [OPTIONS] PATTERN  
    rg [OPTIONS] --help  
    rg [OPTIONS] --version  
  
For more information try --help  
  
 OED  rg "password has to be a string" .  
 OED  rg "password has to" .  
 OED  rg "password has" .  
 OED  rg -i "password has" .  
 OED  rg -i "password" .  

Here I got lots of results, so let's refine our search to just .sh files

 OED  rg -i "password" -g "*.sh" .  
.\src\server\migrations\scripts\dumpDatabase.sh  
8:# Change the password encryption from md5 to scram-sha-256  
9:echo "Changing password encryption to scram-sha-256 ..."  
10:sed -i "s/^#password_encryption = md5/password_encryption = scram-sha-256/" postgres-data/postgresql.conf  
14:echo "Checking password encryption was changed ..."  
15:docker compose exec database psql -U oed -c "SHOW password_encryption;"  
17:# Prompt the user to reset the passwords for users oed and postgres  
18:echo "Please reset password for database user oed"  
19:echo "Should be: $(docker compose exec web printenv OED_DB_PASSWORD)"  
20:docker compose exec database psql -U oed -c "\password oed"  
23:echo "Please reset password for database user postgres"  
24:echo "Should be: $(docker compose exec database printenv POSTGRES_PASSWORD)"  
25:docker compose exec database psql -U oed -c "\password postgres"  
  
.\src\scripts\installOED.sh  
151:            npm run createUser -- $usernameTest password  
155:            npm run createUser -- $usernameTestEmail password  
170:                    printf "%s\n" "User creation had no errors so default user $usernameTest and $usernameTestEmail with password 'password' should exist"  

Okay! That's interesting, let's keep that in pocket for now because I'm thinking we might be barking up the wrong tree here somewhat but important to keep in mind... in case that default user creation /had/ errors, maybe we didn't see that printout user creation... etc..
since our command is npm we're actually looking for a javascript script

npm run testData is a package.json "script" so let's look at package.json and we find

		"testData": "node -e 'require(\"./src/server/data/automatedTestingData.js\").insertSpecialUnitsConversionsMetersGroups()'",  

Aha!
Let's take a look at that file
annnd the word password doesn't show up in this file at all lol
this is where we connect to the database, however, in "insertSpecialUnitsConversionsMetersGroups()" function

	const conn = getConnection();  

it occurs on line 1328
using the language server that got installed for javascript, I can "Go to Definition" of getConnection and get to src/server/db.js on line 21
passwords are commonly set in configs so lines 22-24

	if (connmanager.config === null) {  
		connmanager.config = config.database;  
	}  

let's follow the definition of config
up to line 7

const config = require('./config');  

and I have no idea where or what that is but it should be ... oh wait... it's config.js ? let's go there
(ps I don't like javascript lol)
and boom

const config = {};  
// Database configuration is taken from environment variables (which are loaded by dotenv from the .env file)  
config.database = {  
	user: process.env.OED_DB_USER,  
	database: process.env.OED_DB_DATABASE,  
	password: process.env.OED_DB_PASSWORD,  
	host: process.env.OED_DB_HOST,  
	port: process.env.OED_DB_PORT  
};  

we're getting our password from .env files!
checking back to our compose let's remind ourselves
In the database container:

            - POSTGRES_PASSWORD=pleaseChange # default postgres password that should be changed for security.  

In the web container

            - OED_DB_PASSWORD=opened  

well that might be the issue but let's look back at the documentation again, because I think I remember....
( and I didn't have this problem )
I put this in the channel canvas, I was mis-remembering running cypress with the profile

let's not change anything, reset everything

docker compose down -v  

( use -v to also delete any persistent data - it's not "verbose" lol )
try again and see what happens

docker compose down -v  
docker compose up -d  
docker compose exec web /bin/bash  
# Successful ( with warnings )  
# Check environment variables inside the "web" container  
env  
# (edited)  
Results  
> OED_MAIL_ORG=My Organization Name  
> [email protected]  
> HOSTNAME=710e931d2121  
> [email protected]  
> OED_DB_PORT=5432  
> YARN_VERSION=1.22.19  
> PWD=/usr/src/app  
> OED_MAIL_SMTP=smtp.example.com  
> OED_SERVER_PORT=3000  
> TZ=Etc/UTC  
> OED_DB_TEST_DATABASE=oed_testing  
> OED_DB_USER=oed  
> HOME=/root  
> OED_TOKEN_SECRET=?  
> OED_MAIL_METHOD=none  
> TERM=xterm  
> OED_DB_HOST=database  
> OED_LOG_FILE=log.txt  
> [email protected]  
> SHLVL=1  
> OED_MAIL_SMTP_PORT=465  
> OED_MAIL_CREDENTIAL=credential  
> OED_DB_PASSWORD=opened  
> PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin  
> NODE_VERSION=18.17.1  
> OED_DB_DATABASE=oed  
> OED_PRODUCTION=no  
> _=/usr/bin/env  

going to unset OED_DB_PASSWORD and see if I can recreate the error

 unset OED_DB_PASSWORD  
root@710e931d2121:/usr/src/app# npm run testData  
  
> [email protected] testData  
> node -e 'require("./src/server/data/automatedTestingData.js").insertSpecialUnitsConversionsMetersGroups()'  

See src/server/data/automatedTestingData.js in insertSpecialUnitsConversionsMetersGroups() to see how to remove the data that is being inserted.

look familiar ?
the question of why though... I don't know yet, I'll need some feedback and maybe to look at some outputs on your machine

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment