cursive-flexi-logger-view throwing unhandled error - rust

After I start the application I got the error below and how it looks in the app
mintozzy#laptop:~/tmp/storytel-tui$ cargo run
Finished dev [unoptimized + debuginfo] target(s) in 0.50s
Running `target/debug/storytel-tui`
[flexi_logger][ERRCODE::Time] flexi_logger has to work with UTC rather than with local time, caused by IndeterminateOffset
See https://docs.rs/flexi_logger/latest/flexi_logger/error_info/index.html#time
[flexi_logger][ERRCODE::Write] writing log line failed, caused by Custom { kind: BrokenPipe, error: "cursive callback sink is closed!" }
See https://docs.rs/flexi_logger/latest/flexi_logger/error_info/index.html#write
[dependencies]
reqwest = { version = "0.11.11", features = ["json", "blocking"] }
serde = { version = "1.0.139", features = ["derive"] }
serde_json = "1.0.82"
mpv = "0.2.3"
openssl = { version = "0.10.41" }
cursive = { version = "0.18" , default-features = false, features = ["crossterm-backend"]}
cursive-flexi-logger-view = "^0"
flexi_logger = "0.22.6"
I used the example code https://docs.rs/cursive-flexi-logger-view/latest/cursive_flexi_logger_view/#using-the-flexiloggerview screen is flickering, looks like logger printing below and breaking the UI.
what can be the reason ?

After cursive-flexi-logger-view failing I found that cursive has debug console. I think it is better solution because no need to add another dependency.
To enable debug log added code below
cursive::logger::init();
match std::env::var("RUST_LOG").unwrap_or_else(|_| "info".to_string()).as_ref() {
"trace" => log::set_max_level(LevelFilter::Trace),
"debug" => log::set_max_level(LevelFilter::Debug),
"info" => log::set_max_level(LevelFilter::Info),
"warn" => log::set_max_level(LevelFilter::Warn),
"error" => log::set_max_level(LevelFilter::Error),
_ => log::set_max_level(LevelFilter::Off),
}
siv.add_global_callback('~', Cursive::toggle_debug_console);
with this setup in UI I can enable debug console by typing ~ and it opens the debug window which has logged data in it. Below you can see how it looks
You can find full working code here

Related

Jest Run All Tests(include only/skip) in CI

While in development we occasionally use skip or only to debug a particular test or test suit. Accidentally, we might forget to revert the cases and push the code for PR. I am looking for a way to detect or automatically run all tests even for skip and only tests in our CI pipeline(using Github action). It can be in either case as follow.
Fail the test when there are skip or only tests.
Run all tests even for skip and only.
Very much appreciate any help.
I came up with a solution for the second part of the question about running all tests even for skip and only. I don't think it's elegant solution, but it works and it's easy to implement.
First of all you need to change test runner to jest-circus if you work with jest bellow 27.x version. We need it so our custom test environment will use handleTestEvent function to watch for setup events. To do so, install jest-circus with npm i jest-circus and then in your jest.config.js set testRunner property:
//jest.config.js
module.exports = {
testRunner: 'jest-circus/runner',
...
}
From Jest 27.0 they changed default test runner to jest-circus so you can skip this step if you have this or higher version.
Then you have to write custom test environment. I suggest to write it based on jsdom so for example we also have access to window object in tests and etc. To do so run in terminal npm i jest-environment-jsdom and then create custom environment like so:
//custom-jsdom-environment.js
const JsDomEnvironment = require('jest-environment-jsdom')
class CustomJsDomEnvironment extends JsDomEnvironment {
async handleTestEvent(event, state) {
if(process.env.IS_CI === 'true' && event.name === 'setup') {
this.global.describe.only = this.global.describe
this.global.describe.skip = this.global.describe
this.global.fdescribe = this.global.describe
this.global.xdescribe = this.global.describe
this.global.it.only = this.global.it
this.global.it.skip = this.global.it
this.global.fit = this.global.it
this.global.xit = this.global.it
this.global.test.only = this.global.test
this.global.test.skip = this.global.test
this.global.ftest = this.global.test
this.global.xtest = this.global.test
}
}
}
module.exports = CustomJsDomEnvironment
And inform jest to properly use it:
//jest.config.js
module.exports = {
testRunner: 'jest-circus/runner',
testEnvironment: 'path/to/custom/jsdom/environment.js',
...
}
Then you just have to setup custom environment value IS_CI in your CI pipeline and from now on all your skipped tests will run.
Also in custom test environment you could watch for skipped test and throw an error when your runner find skip/only. Unfortunately throwing an error in this place won't fail a test. You would need to find a way to fail a test outside of a test.
//custom-jsdom-environment.js
const JsDomEnvironment = require('jest-environment-jsdom')
const path = require('path')
class CustomJsDomEnvironment extends JsDomEnvironment {
constructor(config, context) {
super(config, context)
const testPath = context.testPath
this.testFile = path.basename(testPath)
}
async handleTestEvent(event, state) {
if(process.env.IS_CI === 'true' && event.name === 'add_test') {
if(event.mode === 'skip' || event.mode === 'only') {
const msg = `Run ${event.mode} test: '${event.testName}' in ${this.testFile}`
throw new Error(msg)
}
}
}
}
module.exports = CustomJsDomEnvironment

fltk: failed to resolve GlutWindow

I'm trying to follow example of fltk application which uses openGl, but the build is not functioning:
let app = app::App::default();
let mut win = window::GlutWindow::default().with_size(800, 600);
win.set_mode(enums::Mode::Opengl3);
win.end();
win.show();
unsafe {
let gl = glow::Context::from_loader_function(|s| {
win.get_proc_address(s) as *const _
});
I get: failed to resolve: could not find GlutWindow in window.
I'm using fltk version 1
Thank you
p.s. I'm using Rust
Check your imports which are missing from that snippet.
Also if you’re not enabling the enable-glwindow feature, you should, try changing your Cargo.toml to include the missing feature:
[dependencies]
fltk = { version = "1", features = ["enable-glwindow"] }

Configure eslint to report only plugin specific errors

Can eslint be configured to report only a certain subset of errors without explicitly settings all other rules as false
My use case is I want to have a separate report for a11y related errors coming from eslint-plugin-jsx-a11y
So I have a package scripts like
"lint": "eslint .",
"lint.a11y": "eslint --no-eslintrc -c .eslintrc.a11y.js .",
The general config used in lint covers everything and is used in the IDE and during CI to validate code style
The lin.a11y serves only to provide a report on accessibility violations
Currently I use something like this (the idea was borrowed from eslint:all):
const builtInRules = require('eslint/lib/rules');
const disabledRules = {};
for (const [ruleId, rule] of builtInRules) {
if (!rule.meta.deprecated) {
disabledRules[ruleId] = 'off';
}
}
module.exports = {
parser: 'babel-eslint',
extends: ['plugin:jsx-a11y/recommended'],
plugins: ['jsx-a11y'],
rules: {
// Lint only a11y, disable other js style related rules
...disabledRules,
},
};
This almost works, but when there exception to the rules disabled with code comments (disable rule for the line). I'll get an error like "Definition for rule ... was not found":
Definition for rule 'react-hooks/exhaustive-deps' was not found react-hooks/exhaustive-deps
So now I have to import my default eslint configuration, extend it, disable any rules defined there, disable any other rules coming from other plugins, just so that errors for inline comments are disregarded
I created a custom eslint reported that will:
print a general output for all errors including a11y
save a report containing only a11y errors/warnings
custom-lint-formatter.js
const fs = require('fs');
const fileFormatter = require('eslint/lib/cli-engine/formatters/html');
const outputFormatter = require('eslint/lib/cli-engine/formatters/stylish');
function formatter(results = [], data) {
saveA11yReport(results, data);
const output = outputFormatter(results, data);
return output;
}
function saveA11yReport(results, data) {
// a11y errors and warnings
const a11yRelated = results
.filter(r => r.messages.some(m => m.ruleId.startsWith('jsx-a11y/')))
.map(r => {
const messages = r.messages.filter(m => m.ruleId.startsWith('jsx-a11y/'));
return {
...r,
messages,
errorCount: messages.filter(m => m.severity == 2).length,
warningCount: messages.filter(m => m.severity == 1).length,
};
});
const a11yHtml = fileFormatter(a11yRelated, data);
fs.writeFileSync('./dist/a11y.report.html', a11yHtml, 'utf8');
}
module.exports = formatter;
usage:
eslint -f ./custom-lint-formatter.js "./src/**/*.{js,jsx,ts,tsx}"

Not receiving DistributedNotificationCenter in Swift Command Line Tool

I'm building a small app in node.js that uses execa to read print statements coming from a compiled Swift application. The idea is similar to Sindre Sorhus' (who else!?) do-not-disturb
Although I'm no Swift-programmer, I put together a pretty straightforward solution. The binary is compiled by running swift build --configuration=release from the CL to be used in a node-app. It also compiles fine (without the CLI-part) in a Swift playground from XCode and I can see the correct print statements coming in.
import Cocoa
var isLocked:Bool = false
DistributedNotificationCenter.default().addObserver(forName: .init("com.apple.isScreenLocked"), object: nil, queue: nil) { notification in
print("Screen is locked")
isLocked = true
}
DistributedNotificationCenter.default().addObserver(forName: .init("com.apple.isScreenUnlocked"), object: nil, queue: nil) { notification in
print("Screen is unlocked")
isLocked = false
}
struct CLI {
static var standardInput = FileHandle.standardInput
static var standardOutput = FileHandle.standardOutput
static var standardError = FileHandle.standardError
static let arguments = Array(CommandLine.arguments.dropFirst(1))
}
switch CLI.arguments.first {
case "status":
print(isLocked)
default:
print("Unsupported command", to: .standardError)
exit(1)
}
// Some other functions omitted for brevity
Now, when I run the code below from Node.js, everything seems to be working fine. However for some reason, the observer doesn't receive the notification.
'use strict';
const execa = require('execa');
const electronUtil = require('electron-util/node');
const binary = path.join(electronUtil.fixPathForAsarUnpack(__dirname), 'IsLockedOrNot');
setInterval(async () => {
const {stdout} = await execa(binary, ['status']);
console.log(stdout) // keeps logging false, also when screen is locked
}, 1000)
Does anyone have any idea WHY the notifications are not being received in this scenario? I tried various things, like explicitly disabling sleep mode shell.exec('sudo pmset -a disablesleep 1')and compiling the app with the --disable-sandbox flag. No luck however until know..
Use spawn from the base child_process library not execa, make sure you are following stdout, and the most important part for nodejs and swift is that you flush the buffer after every line. Otherwise you have to wait for the program to die before you receive any output. Use "import Darwin.C" and "fflush(stdout)" after every "print" where you want a 'newline'

geb as an additional module using android studio cant find GebConfig.groovy

I get the error Caught: geb.error.NoBaseUrlDefinedException: There is no base URL configured and it was requested.
My main module, i assume is default because its got a green dot at the bottom right, is called app and runs some appium tests.
This module called website(little blue line thing) has a java package called geb where both GebConfig.groovy and my groovy script are located. It's very simple:
package geb;
import geb.Browser
Browser.drive {
go("/some/site")
}
and my config:
package geb
import org.openqa.selenium.chrome.ChromeDriver
import org.openqa.selenium.ie.InternetExplorerDriver
path = 'c:\\drivers\\'
waiting {
timeout = 2
retryInterval = 0.5
preset{
slow{
timeout = 20
retryInterval = 1
}
verySlow{
timeout = 50
}
}
}
environments {
chrome {
drive='chromedriver.exe'
system='webdriver.chrome.driver'
fpath= path+drive
System.setProperty(system,fpath)
driver = { new ChromeDriver() }
}
ie {
drive='IEDriverServer.exe'
system='webdriver.ie.driver'
fpath= path+drive
System.setProperty(system,fpath)
driver = { new InternetExplorerDriver() }
}
}
driver = {new InternetExplorerDriver()}
baseUrl = "http://www.google.com"
reportDir = 'c:\\reports\\'
I have tried manually setting the buildurl to no avail, I've gone through the manual but i couldnt get the classpath set, or atleast when i tried that gave me a whole new set of issues.
What am i doing wrong?

Resources