Skip to content
This repository has been archived by the owner on Jan 6, 2022. It is now read-only.

Graceful dat.json title update #537

Merged
merged 1 commit into from
Jun 14, 2018

Conversation

soyuka
Copy link
Collaborator

@soyuka soyuka commented Jun 12, 2018

#458 (comment)

Not sure if we should ignore completely the title update if the dat.json file doesn't exist.

Copy link
Collaborator

@martinheidegger martinheidegger left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I took some time and look into this and I dont think this solves our problem.

  • There are many reasons why reading could fail, simply ignoring the error doesn't seem like the right approach.
  • The error of "writeFile" is not caught.
  • The metadata could contain data other than title and in case it cant be read: writing it seems like it could be harmful.

In the master branch, the dat's metadata is used to copy from and then a write happens on the harddisk. Which means that read errors can not occur and the error on write is also handled:

https://github.com/dat-land/dat-desktop/blob/5af70eb010b202d9e5af9d09a8909b92db3330db/models/dats.js#L158-L163

This seems to be the better way to go about it.

@soyuka
Copy link
Collaborator Author

soyuka commented Jun 12, 2018

Completely agree on this. However, I'm not sure on how I can get the metadata properly, I've attempted a better fix in my last commit.

@@ -1,7 +1,7 @@
'use strict'

const defaultState = {
dats: [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this can simply be changed into an object. dats is used as an array to show the list.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it's used as an object in the reducer (indexed by key if I'm not mistaken). This looked like a typo to me but I'll investigate further!

metadata = await readFile(filePath)
metadata = JSON.parse(blob)
} catch (_) {
metadata = getState().dats[key].metadata
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think its ambiguous to use either the file or the metadata, shouldn't this be just the metadata?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also: Theoretically the dat doesn't need to exist. Would be good to have an error here if it doesnt

Copy link
Collaborator Author

@soyuka soyuka Jun 12, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

mhh, I though so as well at first but this action is only used when changing a dat's title in the view so the assumption seemed alright!

@martinheidegger
Copy link
Collaborator

standard: Use JavaScript Standard Style (https://standardjs.com) /Users/travis/build/dat-land/dat-desktop/app/actions/index.js:270:27: 'blob' is not defined.

@soyuka
Copy link
Collaborator Author

soyuka commented Jun 13, 2018

ping @martinheidegger I've updated the PR

@martinheidegger
Copy link
Collaborator

Hello @soyuka - Sorry for the delay, was stuck in other things.

@martinheidegger martinheidegger merged commit 29b6102 into dat-ecosystem-archive:react Jun 14, 2018
@soyuka soyuka deleted the update-title branch June 14, 2018 07:25
@soyuka
Copy link
Collaborator Author

soyuka commented Jun 14, 2018

Sorry for the delay, was stuck in other things.

Oh no problem wasn't sure you saw my update! Cheers!

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

Successfully merging this pull request may close these issues.

2 participants