Skip to content
This repository has been archived by the owner on Aug 23, 2021. It is now read-only.

Duplicate content path added in sys { filename } query on windows #259

Open
B-Stewart opened this issue Jun 15, 2021 · 0 comments
Open

Duplicate content path added in sys { filename } query on windows #259

B-Stewart opened this issue Jun 15, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@B-Stewart
Copy link

Description

Describe the issue that you're seeing.

A query like

{
  getPostsList{
    sys {
      filename
    }
  }
}

Will return with an error message like this:

{
  "errors": [
    {
      "message": "ENOENT: no such file or directory, open 'C:\\<abs_path_to_project>\\content\\posts\\content\\posts\\voteForPedro.md'",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [
        "getPostsList"
      ]
    }
  ],
  "data": {
    "getPostsList": null
  }
}

Because the path in the file system it is looking for contains two /content/posts instead of one.

Steps to reproduce

Clear steps describing how to reproduce the issue. Please please please link to a demo project if possible, this makes your issue much easier to diagnose (seriously).

  1. Clone https://github.com/tinacms/tina-cloud-starter
  2. Manually bump packages to fix Failed to launch dev server on Windows tina-cloud-starter#52
"tina-graphql-gateway-cli": "0.2.45"
"tina-graphql-gateway": "0.2.14"
  1. Run the dev graphql server
  2. Run this query against http://localhost:4001/graphql
{
  getPostsList{
    sys {
      filename
    }
  }
}

Expected result

What should happen?

Content's file info should return from /content/posts/voteForPedro.md

Actual result

What actually happened?

/content/posts/voteForPedro.md cannot be found because it is looking for /content/posts/content/posts/voteForPedro.md which adds a duplicate /content/posts/

In triaging I found that this line

returns the following

args.fullPath: 'content\\posts\\voteForPedro.md'
sectionData.path: 'content/posts'

Because the backslashes don't match, the string.replace fails to remove the section data from the relative path. Then the following happens.

const fullPath = p.join(this.rootPath, sectionData.path, relativePath)

And so when the paths are concatted together here it takes this and duplicates the section data with relative path, because it expects relative path to have already been stripped of sectionData

this.rootPath: `C:\<correct_abs_path_to_project>`,
sectionData.path: `content/posts`
relativePath: `content\posts\voteForPedro.md`

So the expectation would be to treat all file paths as file paths, not string file paths because I'm assuming the issue here is how windows vs unix treats forward and backslashes in file paths.

Environment

Tinacms Package Versions

"tina-graphql-gateway-cli": "0.2.48"
"tina-graphql-gateway": "0.2.14",
"tinacms": "0.41.0",

Tools

Tool Version
browser Firefox 88.0.1
os Windows 10.0.19042 Build 19042
node 14.17.0
npm 6.14.13
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant