felixhageloh / uebersicht

ˈyːbɐˌzɪçt
GNU General Public License v3.0
4.59k stars 165 forks source link

intermittent error? #532

Open Robert-Black opened 2 months ago

Robert-Black commented 2 months ago

This is probably my bad coding, but I’m seeing an odd intermittent (but frequent enough to be annoying) error with Übersicht…

Multiple times a day, I get an error panel on my desktop, but if I refresh Übersicht it disappears only to reappear randomly-ish later, and then tends to stay around until I do a manual refresh.

At first I thought it might be the a problem with the shell command being run, having some sort of race condition, but I’ve verified that this still happens without the shell command, so that means there’s either a silly bug in my code, or my code is triggering something within Übersicht. My money’s on the former, so can anyone see where the problem is? The intermittent nature of it has me stumped ¯\_(ツ)_/¯

I almost forgot to add, I have the widget on multiple monitors, and sometimes the error only appears on one monitor, sometimes on both.

import { css } from "uebersicht";
import { run } from "uebersicht";

export const refreshFrequency = 601000;
export const command = "echo `cat '/Users/x/Library/Mobile Documents/com~apple~CloudDocs/file1.txt' '/Users/x/Library/Mobile Documents/com~apple~CloudDocs/Time Tracking/delimiter.txt' '/Users/x/Library/Mobile Documents/com~apple~CloudDocs/Time Tracking/file2.txt' '/Users/x/Library/Mobile Documents/com~apple~CloudDocs/Time Tracking/delimiter.txt' '/Users/x/Library/Mobile Documents/com~apple~CloudDocs/Time Tracking/file3.txt'  `";

export const className =`
  right: 1100px; top: 200px; width: 800px;  /* cut for length */ 
  h1 { /* cut for length */ }
  p { /* cut for length */ }
  p.main { /* cut for length */ }
  p.main span {  /* cut for length */ }
  p.extra { /* cut for length */ }
  .previousTimeTaken { /* cut for length */ }
  div { /* cut for length */ }
`

export const render = ({output}) => {
  var x = output.split('|');
  var previousTimeTaken = x[1].split('(');
  previousTimeTaken = "("+previousTimeTaken[1];

  var previousDescription = x[1].replace(previousTimeTaken,'');

  return (
    <div>
      <h1>stuff</h1>
      <p class='main'>{x[0]}<span> since&nbsp;{x[2]}</span></p>
      <p class='extra'>↖ {previousDescription} <span class='previousTimeTaken'>{previousTimeTaken}</span></p>
    </div>
  );
}

test

felixhageloh commented 2 months ago

your command probably encounters an error and output is undefined in that case. You can do two things:

Just make sure that output is defined

export const render = ({output}) => {
  if (output == null) return null;

  ...
}

or check whether there is an error and then display it. That way you might be able to figure out what the issue is:

export const render = ({output, error}) => {
  if (error != null) return <div>{JSON.stringify(error)}</div>;

  ....
}
Robert-Black commented 2 months ago

Thanks! I'll give that a try and report back.

Robert-Black commented 2 months ago

Curious. Here's the result…

Screenshot of BBEdit at 18 Sep 2024 at 6_15_22 pm

felixhageloh commented 2 months ago

your output must be empty in some cases, so maybe best to combine both approaches:


export const render = ({output, error}) => {
  if (error != null) return <div>{JSON.stringify(error)}</div>;
  if (!output) return null;
  ....
} 
Robert-Black commented 2 months ago

That did the trick! Thank you.

BTW, switched to Sequoia today, and Übersicht hasn't skipped a beat.