question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[BUG] Get value with Buffer type doesn't work

See original GitHub issue

Summary:

Getting an item which has a Buffer inside it doesn’t work.

Code sample:

const User = dynamoose.model('User', {
    "id": String,
    "data": Buffer,
});

new dynamoose.Table('User', [User]);

const item = await User.create({
    id: '1',
    data: Buffer.from('test'),
}, {
    overwrite: true
});

console.log(await item.toDynamo())
// { id: { S: '1' }, data: { B: <Buffer 74 65 73 74> } }

console.log(item.toJSON())
// { id: '1', data: { type: 'Buffer', data: [ 116, 101, 115, 116 ] } }

await User.get('1')

Current output and behavior (including stack trace):

TypeMismatch: Expected data to be of type buffer, instead found type object.
    at checkTypeFunction (/home/project/node_modules/dynamoose/dist/Item.js:316:27)
    at Array.map (<anonymous>)
    at Item.objectFromSchema (/home/project/node_modules/dynamoose/dist/Item.js:341:128)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async Item.conformToSchema (/home/project/node_modules/dynamoose/dist/Item.js:526:28)
    at async /home/project/node_modules/dynamoose/dist/Model/index.js:723:40
    at async file:///home/project/index.mjs:19:1

Expected output and behavior:

The data should be returned correctly, in a JSON form.

Environment:

Operating System: Manjaro Operating System Version: 21.2.6 Node.js version (node -v): v14.17.6 NPM version: (npm -v): 8.5.5 Dynamoose version: 3.0.0-beta.1

Other information (if applicable):

I’m not sure if this is useful but I found that you are missing this from utils/deep_copy.js:

// Handle Uint8Array
if(obj instanceof Uint8Array) {
    copy = new Uint8Array(obj);
    return copy;
}

Even with this it didn’t work, but maybe it’s a lead.

Other:

  • I have read through the Dynamoose documentation before posting this issue
  • I have searched through the GitHub issues (including closed issues) and pull requests to ensure this issue has not already been raised before
  • I have searched the internet and Stack Overflow to ensure this issue hasn’t been raised or answered before
  • I have tested the code provided and am confident it doesn’t work as intended
  • I have filled out all fields above
  • I am running the latest version of Dynamoose

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
fishcharliecommented, Aug 8, 2022

@Drarig29 Of course. Should be available in the latest beta. Let me know if you run into anymore issues.

0reactions
Drarig29commented, Aug 8, 2022

Thank you @fishcharlie!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Buffer doesn't throw error for invalid parameter type · Issue #210
In Node.js 0.10, invalid parameter type String will cause some Buffer APIs, like writeUint32LE('some string', 0), throwing an "value is out ...
Read more >
TS2345:Argument of type 'Buffer' is not assignable to ...
I think the error is thrown on the input parameter of JSON.parse . Try to first call toString on it then pass to...
Read more >
Error Codes - Buffer API
HTTP Code Error Code Description 401 401 Unauthorized. 403 403 Permission denied. 404 404 Endpoint not found.
Read more >
What is a Buffer Overflow? How Do These Types of Attacks ...
A buffer overflow occurs when a program or process attempts to write more data to a fixed-length block of memory, or buffer, than...
Read more >
VISA Flush I/O Buffer doesn't work on my Serial Write and ...
Hello, I've been working on a serial interface .vi that communicate with simple GPRS/3G modems via AT commands. This VI is working very...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found