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

Bug report #2301

Closed
laurentbonet opened this issue Apr 9, 2024 · 2 comments
Closed

Bug report #2301

laurentbonet opened this issue Apr 9, 2024 · 2 comments
Labels
bug Something isn't working.

Comments

@laurentbonet
Copy link

What happened?

Dataview (for inline JS query 'dv.list(app.workspace.getLastOpenFiles().map(function(x){return(dv.page(x).file)}))'): TypeError: Cannot read properties of undefined (reading 'file')

DQL

No response

JS

$=dv.list(app.workspace.getLastOpenFiles().map(function(x){return(dv.page(x).file)}))

The request has worked once, but do not work anymore ...

For info the following request is working well

`$=dv.page(app.workspace.getLastOpenFiles()[0]).file`

resulting in

path: 001-Home/lastViewed.md, folder: 001-Home, name: lastViewed, link: lastViewed, outlinks: <empty list>, inlinks: home, etags: <empty list>, tags: <empty list>, aliases: <empty list>, lists: <empty list>, tasks: <empty list>, ctime: 5:25 PM - avril 09, 2024, cday: avril 09, 2024, mtime: 6:53 PM - avril 09, 2024, mday: avril 09, 2024, size: 541, starred: false, frontmatter: <empty object>, ext: md

Dataview Version

0.5.66

Obsidian Version

1.5.12

OS

MacOS

@laurentbonet laurentbonet added the bug Something isn't working. label Apr 9, 2024
@GottZ
Copy link
Contributor

GottZ commented Apr 11, 2024

you are accessing the file property on an undefined object.
this is not a dataview issue.

try this:

`$=dv.list(app.workspace.getLastOpenFiles().map(path => typeof dv.page(path) + " - " + path))`

image
as you can see in my case, non-notes are not pages so obviously, dv.page will not return a page in said case.

what you CAN do, is this:

`$=dv.list(app.workspace.getLastOpenFiles().map(x=>dv.page(x)).filter(x=>x).map(x=>x.file))`

@laurentbonet
Copy link
Author

Thx so much for the answer !!!
Testing the type of solved my issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working.
Projects
None yet
Development

No branches or pull requests

2 participants