Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Standardize error codes #2901

Closed
mikeal opened this issue Jun 11, 2018 · 2 comments
Closed

Standardize error codes #2901

mikeal opened this issue Jun 11, 2018 · 2 comments
Assignees
Labels
awesome endeavour exp/expert Having worked on the specific codebase is important kind/enhancement A net-new feature or improvement to an existing feature kind/maybe-in-helia

Comments

@mikeal
Copy link
Contributor

mikeal commented Jun 11, 2018

It's fairly standard practice to assign error codes of some sort to the exceptions in order to be less dependent on parsing the text of the error messages. Example:

const getJSON = async (ipfs, path) => {
  let buff = null
  try {
    buff = await ipfs.files.read(path)
  } catch (e) {
    if (e.message !== 'file does not exist') throw e
  }
  if (!buff) return buff
  return JSON.parse(buff.toString())
}

This means that the error message is effectively part of the API and changing it will break compatibility, which we probably don't want.

Also, since we have a standard API across implementations in the same language (js-ipfs, js-ipfs-api) we can write new modules that allow the API implementation to be passed in. But, if part of that API does some error checking we would need the messages to be 100% consistent or have a standardized error code across them.

const getJSON = async (ipfs, path) => {
  let buff = null
  try {
    buff = await ipfs.files.read(path)
  } catch (e) {
    if (e.code !== 404) throw e
  }
  if (!buff) return buff
  return JSON.parse(buff.toString())
}
@achingbrain achingbrain transferred this issue from ipfs-inactive/interface-js-ipfs-core Mar 10, 2020
@achingbrain achingbrain added awesome endeavour exp/expert Having worked on the specific codebase is important kind/enhancement A net-new feature or improvement to an existing feature labels Mar 10, 2020
@achingbrain
Copy link
Member

Yes please. Some motion has been made toward this but really we need to implement the same thing in go-ipfs' http api.

@SgtPooki SgtPooki moved this to 🥞 Todo in js-ipfs deprecation May 17, 2023
@whizzzkid whizzzkid moved this from 🥞 Todo to 🛑 Blocked in js-ipfs deprecation May 24, 2023
@whizzzkid
Copy link

js-ipfs is being deprecated in favor of Helia. You can #4336 and read the migration guide.

Please feel to reopen with any comments before 2023-06-05. We will do a final pass on reopened issues afterward (see #4336).

This might already be resolved in Helia, if not please feel free to create an issue there.

@github-project-automation github-project-automation bot moved this from 🛑 Blocked to ✅ Done in js-ipfs deprecation May 31, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
awesome endeavour exp/expert Having worked on the specific codebase is important kind/enhancement A net-new feature or improvement to an existing feature kind/maybe-in-helia
Projects
No open projects
Status: Done
Development

No branches or pull requests

3 participants