chrishasz / spgo

SPGo: A Lightweight, Open Source, SharePoint IDE for Visual Studio Code
https://www.chrishasz.com/spgo
MIT License
60 stars 11 forks source link

Error while populating workspace, no info provided #122

Closed LuisPeregrinaPSL closed 3 years ago

LuisPeregrinaPSL commented 4 years ago

Note: for support questions, please use stackoverflow and tag the post with #spgo.

[15/7/2020 16:34:25] Cannot read property 'map' of undefined [15/7/2020 16:34:25] Error Detail: [15/7/2020 16:34:25] ---------------------- [15/7/2020 16:34:25] {} [15/7/2020 16:34:25] ===============================================================================

I'm familiar with javascript/node ecosystem, is there a way to debug or get a better log level for the output of this plugin?

LuisPeregrinaPSL commented 4 years ago

Note, I'm not admin in sharepoint, I only have access to the folder in remoteFolders

LuisPeregrinaPSL commented 4 years ago

Getting the server version also shows the same error. Could it be a problem with auth?

chrishasz commented 4 years ago

Hello @LuisPeregrinaPSL -

I agree with you that this is likely an authentication issue.

VSCode does have an advanced debugging tool - to enable it go to Help -> Toggle Development Tools, or using <ctrl-shift-i> (windows). This opens the chrome developer console and you can view much of the console logging statements that are not made available in the extension context or output window.

Second - I do need to continue refining the SPGo output/debug logging components. I've found that SP auth errors do not JSON.stringify() at all - which is why you see the empty output:

15/7/2020 16:34:25] Error Detail:
[15/7/2020 16:34:25] ----------------------
[15/7/2020 16:34:25] {}

Let me know the detailed errors you are seeing and I'll keep working to improve logging.

LuisPeregrinaPSL commented 4 years ago

Unfortunately I can't find any reference to spgo in the developer tools, it seems vscode uses another process to run extensions.

LuisPeregrinaPSL commented 4 years ago

When I use bad credentials I get something I would expect as an error message:

[17/7/2020 9:57:46] ================================     ERROR     ================================

[17/7/2020 9:57:46] <s:Fault>
  <s:Code>
    <s:Value>s:Sender</s:Value>
    <s:Subcode>
      <s:Value xmlns:a="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">a:FailedAuthentication</s:Value>
    </s:Subcode>
  </s:Code>
  <s:Reason>
    <s:Text xml:lang="en-US">ID3242: The security token could not be authenticated or authorized.</s:Text>
  </s:Reason>
</s:Fault>
[17/7/2020 9:57:46] Error Detail:
[17/7/2020 9:57:46] ----------------------
[17/7/2020 9:57:46] {}
[17/7/2020 9:57:46] ===============================================================================
LuisPeregrinaPSL commented 4 years ago

Used digest, it said 0 files, changed back to ADFS and now the console shows this: Error in getFolderContent: Cannot read property 'map' of undefined

chrishasz commented 4 years ago

Hello @LuisPeregrinaPSL

I'm still trying to track down the root cause of this issue. I grabbed the latest source for sppull, the library that SPGo uses to download files from SharePoint, and there are two map statement in the getFolderContent

87.     let metadataStr: string = this.options.metaFields.map(fieldName => {

...and

121.    files: (response.body.d.Files.results || []).map((file) => {

I suspect the second instance on line 121 is the cause of the error. This would indicate that the response from the SharePoint API is something other than a list of objects (e.g. an error, or something else).

Since you are familiar with JS + Node apps, I was wondering if you could help me debug using the following steps:

  1. create a new JS/TS project from the sample code under the basic usage header in the sppull readme.
  2. update the authentication to use ADFS as described here
  3. run the file and let me know if you still see the error. If not, please share how you configured the context and options objects.

I can then compare that to how SPGo manages these objects and hopefully I can find the root cause.

Thanks for your help!

LuisPeregrinaPSL commented 4 years ago

Ok, the error is coming from that package, here is the offending line: \node-sp-auth\lib\src\auth\resolvers\AdfsCredentials.js:55:22

LuisPeregrinaPSL commented 4 years ago

Using ondemand showed a login page and that went through without a problem

chrishasz commented 4 years ago

Thanks for your quick response!

Can you share the following code files you wrote (please mask password info) so that I can create an issue in the node-so-auth repo?

LuisPeregrinaPSL commented 4 years ago

package.json:

{
  "name": "sharepoint",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node index.js"
  },
  "author": "",
  "license": "ISC",
  "dependencies": {
    "sppull": "^2.6.6"
  }
}

index.js:

const { sppull } = require("sppull");

const context = {
  siteUrl: "https://xxx.sharepoint.com/sites/xxx",
  creds: {
    username: "xxx@xxx", 
    password: "xxx",
    relyingParty: "urn:federation:MicrosoftOnline",
    adfsUrl: "https://xxx/adfs/ls/"
  }
};

const options = {
  spRootFolder: "/xxx/",
  dlRootFolder: "./src"
};

sppull(context, options)
  .then((downloadResults) => {
    console.log("Files are downloaded");
    console.log("For more, please check the results", JSON.stringify(downloadResults));
  })
  .catch((err) => {
    console.log("Core error has happened", err);
  });
chrishasz commented 4 years ago

@LuisPeregrinaPSL - unfortunately VSCode blocks the external window, so I am not able to use the ondemand/interactive authentication functionality in node-sp-auth.

Did you see the same error Cannot read property 'map' of undefined with your test app?

chrishasz commented 3 years ago

@LuisPeregrinaPSL - do you have any updates on testing, or was VSCode eating the interactive login window a deal breaker on this one?

LuisPeregrinaIBM2 commented 3 years ago

Sorry, forgot about this one, I stopped using it.

chrishasz commented 3 years ago

Closing.