Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
thesiti92 opened this issue Jan 22, 2018 · 17 comments
Closed

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

thesiti92 opened this issue Jan 22, 2018 · 17 comments

Comments

@thesiti92
Copy link
Contributor

thesiti92 commented Jan 22, 2018

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:

    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.<anonymous> (/usr/lib/node_modules/@google/clasp/node_modules/request/request.js:1163:10)
    at Request.emit (events.js:159:13)
    at IncomingMessage.<anonymous> (/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 called build/Main.gs and should be pushed from the build directory.
2. 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/clasp@1.0.7
  • OS (Mac/Linux/Windows): Windows 10, WSL running Ubuntu 16.04
@grant
Copy link
Contributor

grant commented Jan 22, 2018

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.

@thesiti92
Copy link
Contributor Author

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.

@grant
Copy link
Contributor

grant commented Jan 23, 2018

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.

@thesiti92
Copy link
Contributor Author

thesiti92 commented Jan 23, 2018

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.

@grant
Copy link
Contributor

grant commented Jan 23, 2018

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.

@thesiti92
Copy link
Contributor Author

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!

@grant
Copy link
Contributor

grant commented Jan 23, 2018

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...

@grant
Copy link
Contributor

grant commented Jan 25, 2018

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

@thomasbholman
Copy link

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.

@nirazul
Copy link
Contributor

nirazul commented Jun 5, 2018

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

@grant
Copy link
Contributor

grant commented Jun 5, 2018

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

@grant
Copy link
Contributor

grant commented Jun 27, 2018

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"

@paxperscientiam
Copy link

paxperscientiam commented Aug 19, 2018

@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.

@grant grant reopened this Aug 19, 2018
@grant
Copy link
Contributor

grant commented Oct 9, 2018

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.

@grant
Copy link
Contributor

grant commented Oct 29, 2018

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

@grant grant closed this as completed Oct 29, 2018
@paxperscientiam
Copy link

@nirazul

malformed

jsonlint works well.

@paxperscientiam
Copy link

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."

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants