littledivy / autopilot-deno

:rocket: Cross-platform desktop automation module for Deno.
https://autopilot.mod.land
MIT License
492 stars 15 forks source link

Fatal Runtime Error #6

Closed tionis closed 4 years ago

tionis commented 4 years ago

After following the fixes from #3 I get rust panic with following stacktrace:

thread '<unnamed>' panicked at 'called `Result::unwrap()` on an `Err` value: Error("invalid type: null, expected f64", line: 1, column: 9)', src/lib.rs:108:34
stack backtrace:
   0: backtrace::backtrace::libunwind::trace
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/libunwind.rs:86
   1: backtrace::backtrace::trace_unsynchronized
             at /cargo/registry/src/github.com-1ecc6299db9ec823/backtrace-0.3.44/src/backtrace/mod.rs:66
   2: std::sys_common::backtrace::_print_fmt
             at src/libstd/sys_common/backtrace.rs:78
   3: <std::sys_common::backtrace::_print::DisplayBacktrace as core::fmt::Display>::fmt
             at src/libstd/sys_common/backtrace.rs:59
   4: core::fmt::write
             at src/libcore/fmt/mod.rs:1063
   5: std::io::Write::write_fmt
             at src/libstd/io/mod.rs:1426
   6: std::sys_common::backtrace::_print
             at src/libstd/sys_common/backtrace.rs:62
   7: std::sys_common::backtrace::print
             at src/libstd/sys_common/backtrace.rs:49
   8: std::panicking::default_hook::{{closure}}
             at src/libstd/panicking.rs:204
   9: std::panicking::default_hook
             at src/libstd/panicking.rs:224
  10: std::panicking::rust_panic_with_hook
             at src/libstd/panicking.rs:470
  11: rust_begin_unwind
             at src/libstd/panicking.rs:378
  12: core::panicking::panic_fmt
             at src/libcore/panicking.rs:85
  13: core::option::expect_none_failed
             at src/libcore/option.rs:1211
  14: core::result::Result<T,E>::unwrap
             at /rustc/8d69840ab92ea7f4d323420088dd8c9775f180cd/src/libcore/result.rs:1003
  15: autopilot_deno::op_move_mouse
             at src/lib.rs:108
  16: <deno::ops::plugin::PluginInterface as deno_core::plugin_api::Interface>::register_op::{{closure}}
  17: deno_core::isolate::CoreIsolate::dispatch_op
  18: deno_core::bindings::send
  19: <extern "C" fn(A0) .> R as rusty_v8::support::CFnFrom<F>>::mapping::c_fn
  20: _ZN2v88internal25FunctionCallbackArguments4CallENS0_15CallHandlerInfoE
  21: _ZN2v88internal12_GLOBAL__N_119HandleApiCallHelperILb0EEENS0_11MaybeHandleINS0_6ObjectEEEPNS0_7IsolateENS0_6HandleINS0_10HeapObjectEEESA_NS8_INS0_20FunctionTemplateInfoEEENS8_IS4_EENS0_16BuiltinArgumentsE
  22: _ZN2v88internalL26Builtin_Impl_HandleApiCallENS0_16BuiltinArgumentsEPNS0_7IsolateE
  23: Builtins_CEntry_Return1_DontSaveFPRegs_ArgvOnStack_BuiltinExit
note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace.
fatal runtime error: failed to initiate panic, error 5
Aborted (core dumped)
tionis commented 4 years ago

The Script that was used to produce the issue:

#!/usr/bin/env -S deno run --unstable --allow-net --allow-plugin --allow-env --allow-read --allow-write
import AutoPilot from 'https://raw.githubusercontent.com/divy-work/autopilot-deno/master/mod.ts';
var pilot = new AutoPilot();
var screenSize = pilot.screenSize();
var widthUnit: number = screenSize.heigth / 8;
setInterval(function () {
    var position = pilot.mousePosition();
    if (position.x > widthUnit * 2) {
        pilot.moveMouse(widthUnit,position.y)
    }else{
        pilot.moveMouse(widthUnit*3,position.y)
    }
}, 200);
littledivy commented 4 years ago

@tionis The problem is with your script. The widthUnit is passed as NaN so it breaks(it should be a number). I'll add type checks for the same but this is a problem with your script.

var widthUnit: number = screenSize.heigth / 8; <-- typo with `height`!!
console.log(widthUnit); // <-- this is NaN
littledivy commented 4 years ago

@tionis I've added typechecks for the method arguments. If you try again with the same script, You will get a similar output to this: https://shareit.video/1hvk1lnw6NGNShG0tjVP

tionis commented 4 years ago

I see, the error in the script was a Typo screenSize.heigth to screenSize.height. Seems to be the error of the day for me.