Clasp: "Error: Request contains an invalid argument" on push and deploy

Created on 22 Jan 2018  ·  17Comments  ·  Source: google/clasp

Expected Behavior

Push code to script project

Actual Behavior

Request fails on clasp push and on clasp redeploy. Redeploy has a more verbose error report:

```{ Error: Request contains an invalid argument.
at new RequestError (/usr/lib/node_modules/@google/clasp/node_modules/google-auth-library/lib/transporters.js:34:42)
at Request._callback (/usr/lib/node_modules/@google/clasp/node_modules/google-auth-library/lib/transporters.js:96:27)
at Request.self.callback (/usr/lib/node_modules/@google/clasp/node_modules/request/request.js:186:22)
at Request.emit (events.js:159:13)
at Request. (/usr/lib/node_modules/@google/clasp/node_modules/request/request.js:1163:10)
at Request.emit (events.js:159:13)
at IncomingMessage. (/usr/lib/node_modules/@google/clasp/node_modules/request/request.js:1085:12)
at Object.onceWrapper (events.js:254:19)
at IncomingMessage.emit (events.js:164:20)
at endReadableNT (_stream_readable.js:1062:12)
code: 400,
errors:
[ { message: 'Request contains an invalid argument.',
domain: 'global',
reason: 'badRequest' } ] }

The auth library fails, so i tried logging back in and out and into another account to no avail

## Steps to Reproduce the Problem

  1.  My current project directory looks like: 

├── appsscript.json
├── build
├── node_modules
├── package.json
├── package-lock.json
├── README.md
└── src
`` With src and build as directories. The main apps script in my project is calledbuild/Main.gs` and should be pushed from the build directory.

  1. My build system is currently just using babel to transpile syntax and perform a simple bundle of the src directory.
    Besides that, I don't know what's out of the ordinary with my project. My Google account is personal, not organizational, so the auth issues don't come from that....

Specifications

  • Node version (node -v): v9.3.0
  • Version (npm list | grep clasp): @google/[email protected]
  • OS (Mac/Linux/Windows): Windows 10, WSL running Ubuntu 16.04

All 17 comments

I think you must ignore some files before pushing. i.e. node_modules/.

Create a file called .claspignore. (Works like .gitignore.) Add node_modules/ and package-lock.json as well as other files/folders that should be ignored.

I need to write more details on how to ignore files/folders in the README.

Link the repo if you can so I can look further.

The repo is private, so I cannot link it. I created the .claspignore file and the push/deploy simply errors faster now. The error appears to have to do with some google-auth thing no? Any other bug info I can provide?
Thanks for the quick response @grant.

The main issue is here:

 errors:
   [ { message: 'Request contains an invalid argument.',
       domain: 'global',
       reason: 'badRequest' } ] }

The google-auth is just the stack trace of the request.

This error occurs if there's a bad API request to the Apps Script API. Unfortunately we don't get good reasons for errors from the API.

The best way to debug is to remove all files, try pushing, then slowly add each file back in until clasp/the API breaks. I think the API doesn't allow some characters, which may break clasp.

Can you remove all files and slowly add them back and push? See which file break it.

I did as you suggested and traced the issue node_modules folder, specifically a bug in how you guys ignore directories.
My .claspignore:

# dependencies
/node_modules
/node_modules/wrappy/package.json
node_modules
node_modules/*
./node_modules/*
./node_modules
./node_modules*
*.json
!appsscript.json

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
/.vscode/*
*.md
package.json
package-lock.json
.gitignore
.babelrc
/src  

Console Output:

/addon-test$ clasp push
└─ appsscript.json
└─ build/Main.gs
└─ node_modules/wrappy/package.json
Pushed 3 files.

Yes, I understand my .claspignore is excessive but I just wanted to try everything.
Also, the project directory has just ignored text files, the build folder, and a node_modules folder with just wrappy/package.json in it.

Underneath it all we use anymatch: https://www.npmjs.com/package/anymatch

(Here in clasp: https://github.com/google/clasp/blob/master/index.js#L485)

I'll have to look more to see if this is a bug in anymatch or some config not set.

Fixed it. Anymatch uses syntax different from a traditional .gitignore for directories. Related Issue Here. To ignore directories and subdirectories like node_modules the syntax is **/node_modules/**. I can create a PR to add documentation for it to the README.md if that would help!

Great! I do need to document .claspignore.
A PR would help. Mind adding a section about .claspignore? Something like:

How To...

Ignore Files

... Create a file called .claspignore ... it uses anymatch...

Looking further, I need to do a better job of ignoring files, I think nested package.json files are still pushed.

If anyone else looks through this thread for the mysterious "Error: Request contains an invalid argument" , the issue that caused me recently to get this same error was that I did not have my .git file entered in the .claspignore file. If you have a .git file in that directory, you'll want to place it in your .claspignore file.

Another reason is apparently when your appsscript.json file is malformed. Mine had an additional comma in it, which rendered the request invalid.

  • Perhaps we can ignore .git by default in clasp.
  • Perhaps we can validate appsscript.json before push and during status.

Based off of GitHub analytics, 94 unique people looked at this issue in the last week.

Maybe we should provide a better message than the API response:
"Request contains an invalid argument"

@grant I think this issue should be reopened per your suggestion that the error message be made more specific..

For instance, I just deduced the cause of the vague error message in my situation.

Steps to reproduce:

  • add a URI with http protocol to urlFetchWhitelist in appsscript.json file. (http://example.org)
  • add URI, same as for the above key, but using the https protocol, to openLinkUrlPrefixes. (https://example.org)

Another way:

  • put any URI with the http protocol in urlFetchWhitelist

The above examples produce the error in question, but the error is not produced when the values are switched (https in urlFetchWhitelist and http in openLinkUrlPrefixes.

Per https://github.com/google/clasp/issues/21#issuecomment-394829151, I created a basic appsscript.json JSON validator in https://github.com/google/clasp/commit/80f3f7c1acae4171c00af4ec97356bf0d5ff4abf.

It looks like this:

clasp push
Error: Your appsscript.json contains invalid JSON.

It only detects JSON errors like a trailing comma.

Going to close this issue unless there's something else specific I can do.

@nirazul

malformed

jsonlint works well.

Per #21 (comment), I created a basic appsscript.json JSON validator in 80f3f7c.

It looks like this:

clasp push
Error: Your appsscript.json contains invalid JSON.

It only detects JSON errors like a trailing comma.

Sorry @grant , but it looks like your error message has been replaced with the wrong error message.

When trying to push with a malformed .clasp.json, the current error (as of 1.6.3) is "No .clasp.json settings found. create or clone a project first."

Was this page helpful?
0 / 5 - 0 ratings

Related issues

aandis picture aandis  ·  7Comments

coccoinomane picture coccoinomane  ·  5Comments

dustinmichels picture dustinmichels  ·  4Comments

grant picture grant  ·  4Comments

arichardsmith picture arichardsmith  ·  6Comments