tauri
tauri copied to clipboard
invalid utf-8 sequence of 1 bytes from index XX
Hello!
I'm trying to build a GUI to run some cmd commands I daily use at work but I can't figure out how to make them work. I've read the documentation of the Shell's api but it seems like I'm doing something wrong or it's some kind of bug.
This is the simple code I'm using:
async function ip() {
const result = new Command("ipconfig");
result.on("data", (line) => console.log(line));
result.on("error", (err) => console.error(err));
await result.spawn();
}
return (
<div>
<input type="text" placeholder="Ip Address" />
<button onClick={ip}>Ping</button>
</div>
);
I've done the following scope to make the cmd work:
"tauri": {
"allowlist": {
"shell": {
"all": true,
"execute": true,
"sidecar": true,
"open": true,
"scope": [
{
"name": "ipconfig",
"cmd": "ipconfig"
}
]
},
"dialog": {
"all": true,
"open": true,
"save": true
}
},
And when i try to run the ping from the button, I get the following error:
invalid utf-8 sequence of 1 bytes from index 4
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM174:3
next-dev.js?3515:20
invalid utf-8 sequence of 1 bytes from index 10
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM175:3
next-dev.js?3515:20
invalid utf-8 sequence of 1 bytes from index 4
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM176:3
next-dev.js?3515:20
invalid utf-8 sequence of 1 bytes from index 19
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM181:3
next-dev.js?3515:20
invalid utf-8 sequence of 1 bytes from index 4
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM182:3
next-dev.js?3515:20
invalid utf-8 sequence of 1 bytes from index 10
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM183:3
next-dev.js?3515:20
invalid utf-8 sequence of 1 bytes from index 4
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM184:3
next-dev.js?3515:20
invalid utf-8 sequence of 1 bytes from index 28
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM187:3
next-dev.js?3515:20
invalid utf-8 sequence of 1 bytes from index 19
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM190:3
next-dev.js?3515:20
invalid utf-8 sequence of 1 bytes from index 21
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM192:3
next-dev.js?3515:20
invalid utf-8 sequence of 1 bytes from index 19
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM195:3
next-dev.js?3515:20
invalid utf-8 sequence of 1 bytes from index 21
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM197:3
next-dev.js?3515:20
invalid utf-8 sequence of 1 bytes from index 19
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM200:3
next-dev.js?3515:20
invalid utf-8 sequence of 1 bytes from index 21
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM202:3
next-dev.js?3515:20
invalid utf-8 sequence of 1 bytes from index 19
window.console.error @ next-dev.js?3515:20
eval @ index.jsx?d35c:13
t.emit @ shell-e5849d56.js?2ad8:1
eval @ shell-e5849d56.js?2ad8:1
value @ tauri-a4b3335a.js?67f7:1
(anónimo) @ VM205:3
next-dev.js?3515:20
I'm pretty sure it's my fault but I don't know if it's something on the config side or the code side.
Don't be rude please, it's my first project in coding and I'm kinda new.. Thank you!
Welcome to the Tauri community, and thanks for filing your first issue.
We try to never be rude, and want to encourage you on your software engineering journey. We have a CODE_OF_CONDUCT for the community that you can read more about here:
https://github.com/tauri-apps/tauri/blob/dev/.github/CODE_OF_CONDUCT.md
Now, with regard to your issue:
Please share with us the results of yarn tauri info or cargo tauri info. Its probably something else, but this way we can start eliminating potential causes.
you could try using a different encoding https://tauri.app/v1/api/js/shell#encoding
Welcome to the Tauri community, and thanks for filing your first issue.
We try to never be rude, and want to encourage you on your software engineering journey. We have a CODE_OF_CONDUCT for the community that you can read more about here:
https://github.com/tauri-apps/tauri/blob/dev/.github/CODE_OF_CONDUCT.md
Now, with regard to your issue:
Please share with us the results of
yarn tauri infoorcargo tauri info. Its probably something else, but this way we can start eliminating potential causes.
Thank you! This is the reply i'm getting from running the command:
> [email protected] tauri
> tauri "info"
Environment
› OS: Windows 10.0.22000 X64
› Webview2: 105.0.1343.53
› MSVC:
- Visual Studio Build Tools 2022
› Node.js: 16.14.0
› npm: 8.5.5
› pnpm: Not installed!
› yarn: Not installed!
› rustup: 1.25.1
› rustc: 1.64.0
› cargo: 1.64.0
› Rust toolchain: stable-x86_64-pc-windows-msvc
Packages
› @tauri-apps/cli [NPM]: 1.1.1
› @tauri-apps/api [NPM]: 1.1.0
› tauri [RUST]: 1.1.1,
› tauri-build [RUST]: 1.1.1,
› tao [RUST]: 0.14.0,
› wry [RUST]: 0.21.1,
App
› build-type: bundle
› CSP: unset
› distDir: ../dist
› devPath: http://localhost:1420/
› framework: React (Next.js)
› bundler: Webpack
App directory structure
├─ .next
├─ .vscode
├─ node_modules
├─ src
└─ src-tauri
you could try using a different encoding https://tauri.app/v1/api/js/shell#encoding
This is how i tried with utf-8
await result.spawn({ encoding: "utf-8" });
And this with windows-1252 as i've read on some stackoverflow answers but still got the same result:
await result.spawn({ encoding: "Windows-1252" });
what is your OS locale? can you run ipconfig in a shell and post the raw output here
This should probably be moved to a feature request for supporting IPC responses that transfer raw binary data as a string of escaped bytes. I'm currently dealing with this right now with a console application that responds with msgpack, which is utf-8 for printing characters, but uses non-encoded bytes to represent everything else.
These messages fail to decode with the error above for the same reason, because they are not definitely not valid utf-8, but I need the raw data for my application. Specifying 'utf-8' as the encoding mangles the output because encoding_rs will replace anything invalid with a replacement character.
The only workarounds I can think of right now are to implement a custom command pipeline in src-tauri, or to use an independent shim application to escape the bytes before tauri's command api feeds them to the front end.
An option in the SpawnOptions type could specify that the developer wants an array of bytes returned in data rather than a string.
@LordAntonio99 @Bukmopbl4 this seems like an issue with the encoding of powershell on your system, can you try changing it to to utf8 in your scripts or globally in your profile?
see https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_character_encoding?view=powershell-7.3#changing-the-default-encoding for how to.
It works now
I fixed it using this:
command = new Command("start", [cmd], { encoding: 'utf8' });
I fixed it using this:
command = new Command("start", [cmd], { encoding: 'utf8' });
I'ts worked for me! Thx! <3