Comments (11)
Thanks. Bonus points for an error message when you try to pipe a nonexistent file into stdin. In the C world, the function you'd use is called isatty()
. I trip on that regularly when I mistakenly run the client demo from the src
directory the mint.json
is up in the top-level directory.
from solana.
I'm going to take a stab at this, I'll try to have a PR ready for Monday
from solana.
@rleungx, did you test-drive that "bonus points" case? Easy to imagine that was implicitly handled by your patch. If not, I'll create a separate issue for that.
from solana.
Hi, @garious. I'm not sure about how isatty()
works here. I've changed some code as below.
let mint: Mint = if stdin_isatty() {
serde_json::from_reader(stdin()).unwrap_or_else(|e| {
eprintln!("failed to parse json: {}", e);
exit(1);
})
} else {
eprintln!("file may not exist");
exit(1);
};
Is this correct?
from solana.
"Look before you leap". Are you able to detect no file was passed to stdin before invoking from_reader
?
from solana.
My bad. I've edited the comment. How it looks now?
from solana.
How about something like the following? That way if isatty
isn't available on some platform (Windows?), we can compile it out without any additional restructuring.
if !stdin_isatty() {
eprintln!("file may not exist");
exit(1);
};
let mint: Mint = serde_json::from_reader(stdin()).unwrap_or_else(|e| {
eprintln!("failed to parse json: {}", e);
exit(1);
});
from solana.
I just found that we should use stdin_isatty()
inside unwrap_or_else
as I did before. Because it will always exit if we put stdin_isatty()
before from_reader
, right?
from solana.
There's 4 cases:
- No "cat mint.json |"
- mint.json isn't in the current directory
- mint.json has corrupt data
- mint.json is good
I'm just looking for it to exit early if we can detect either of the first two.
from solana.
Thanks for your explanation! Actually, what I mean is that stdin_isatty
will all return true, except the first one. Any idea about how to make it work?
from solana.
That's perfect. So the thing that should change from my last code sample is just the error message. It should read something like, "nothing found on stdin, expected a JSON file".
For the second case, check if the stream is empty and report an error that says something like, "empty file on stdin, expected a JSON file".
And then the last two are good as-is.
from solana.
Related Issues (20)
- A solana account, not a pda account, accidentally called the system contract to allocate space. Is there a way to withdraw the sol of this account? HOT 1
- Emergency PDA withdrawal with keypair. HOT 1
- [Mainnet v1.18.15] Error with method:getSignatureStatuses HOT 1
- error[E0599]: no variant or associated item named `deserialize` found for enum `StakeState` in the current scope HOT 1
- error: package `solana-program v2.0.0` cannot be built because it HOT 1
- RPC Node Memory Leak Frequently HOT 1
- store more tx_data HOT 1
- store more tx_data HOT 1
- Feature: add serde to type defs in solana-accounts-db HOT 1
- Is pubkey collision possible in devnet? HOT 1
- How could I parser the logs if I want token transfer count, like usdt Es9vMFrzaCERmJfrF4H2FYD4KCoNkY11McCe8BenwNYB, HOT 1
- Solana-program incorrectly uses `jobserver` feature with `cc` HOT 1
- spl-token create-token can't add metadata to new legacy SPL token HOT 1
- solana transfer can't retrieve SOL from a mint address, even if fee payer is different HOT 1
- No Work To Do Error HOT 1
- `simulateTransaction` incorrectly throws `TooManyAccountLocks` for <64 writeable accounts HOT 2
- Compile error when using the `offset_of` macro in solana-program crate HOT 1
- $20 in sol to whoever can help me solve this getrandom error when i run anchor build HOT 1
- loader-v3 programdata account size not counted towards to loaded-accounts-data-size-limit if executed through CPI HOT 1
- attempting to interact with the tpu client HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from solana.