go-watcher icon indicating copy to clipboard operation
go-watcher copied to clipboard

MacOS Catalina: Does not work

Open vonhraban opened this issue 5 years ago • 14 comments

It does not work with the following message:

$ watcher
2019/10/24 21:02:15 build started
Building ....
2019/10/24 21:02:17 build completed
Running ...
2019/10/24 21:02:17 process interrupted: signal: killed

Other people from my team who upgraded to Catalina report the same

$ go version
go version go1.12.9 darwin/amd64

vonhraban avatar Oct 24 '19 18:10 vonhraban

Guys getting the same error on macOS Catalina. @vonhraban Were you able to solve the issue?

puneet-sutar avatar Nov 08 '19 17:11 puneet-sutar

yup same here, i will see if i get some time this evening to find out what's causing this and make a pull request.

dsincl12 avatar Dec 12 '19 11:12 dsincl12

ok i've found the issue and got a fix for it. it's not done yet but the problem is the change to zsh from bash on MacOS Catalina. I will try to get it done tomorrow after work.

If you're on Catalina and just want to get it working, change runCommand() in common.go:

func runCommand(name string, args ...string) (*exec.Cmd, error) {
	var cmd *exec.Cmd

	if len(args) == 0 {
		cmd = exec.CommandContext(context.Background(), "/bin/zsh", "-c", name)
	} else {
		cmd = exec.Command(name, args...)
	}

	stderr, err := cmd.StderrPipe()
	if err != nil {
		return cmd, err
	}

	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return cmd, err
	}

	if err := cmd.Start(); err != nil {
		return cmd, err
	}

	go io.Copy(os.Stdout, stdout)
	go io.Copy(os.Stderr, stderr)

	return cmd, nil
}

and then change Run() in run.go:

func (r *Runner) Run(p *Params) {
	for fileName := range r.start {

		color.Green("Running %s...\n", p.Get("run"))

		cmd, err := runCommand(fileName, p.Package...)
		if err != nil {
			log.Printf("Could not run the go binary: %s \n", err)
			r.kill(cmd)

			continue
		}

		r.cmd = cmd

		go func(cmd *exec.Cmd, fileName string) {
			if err := cmd.Wait(); err != nil {
				log.Printf("process interrupted: %s \n", err)
				r.kill(cmd)
			}

			removeFile(fileName)
		}(r.cmd, fileName)
	}
}

dsincl12 avatar Dec 16 '19 00:12 dsincl12

Uhm... seems to be even simpler. You only need to make the change to Run() (i.e. moving removeFile()).

dsincl12 avatar Dec 16 '19 12:12 dsincl12

I had to add this line before runCommand in Run func: fileName = "./" + fileName

It was trying to search for fileName in PATH.. maybe I'm missing something.

I've also added removeFile to the err handler of runCommand, right before continue. To don't leave any invalid executable around...

dedo1911 avatar Dec 27 '19 13:12 dedo1911

Hello, after cloning and installin golang watcher, try to type watcher on my terminal, on cd /path/to/myapp directory following error returns:

zsh: command not found: watcher

Could you please advice what is wrong?

Btw, I am using MacOS Catalina

Thanks for your support

zzeynal avatar Jun 09 '20 19:06 zzeynal

@zzeynal Not sure why you added your question to this issue, but here's your problem: Just because you are in the folder, it doesn't mean that folder is in your $PATH. You can do one of two things: add that folder to your $PATH environment variable, or just run ./watcher. You may need to chmod +x ./watcher first if it's not already executable.

tzusman avatar Jun 09 '20 20:06 tzusman

@zzeynal Not sure why you added your question to this issue, but here's your problem: Just because you are in the folder, it doesn't mean that folder is in your $PATH. You can do one of two things: add that folder to your $PATH environment variable, or just run ./watcher. You may need to chmod +x ./watcher first if it's not already executable.

# @tzusman Thanks for your reply.

Somehow I have fixed and watcher command already works. But now I have same issue with building and running the myapp.

Building .... 2020/06/12 19:28:11 build completed Running ... 2020/06/12 19:28:11 process interrupted: signal: killed

It does not build any executable file nor runs any, as there does not appear any exeucatble file.

While nomral outcome instead of above outcome, should look like as the below:

Building .... 2020/06/12 19:28:11 build completed Running ... 2020/06/12 19:28:11 process interrupted: signal: killed [GIN-debug] [WARNING] Creating an Engine instance with the Logger and Recovery middleware already attached.

[GIN-debug] [WARNING] Running in "debug" mode. Switch to "release" mode in production.

  • using env: export GIN_MODE=release
  • using code: gin.SetMode(gin.ReleaseMode)

[GIN-debug] GET /posts --> main.Posts (3 handlers) [GIN-debug] GET /posts/:id --> main.Show (3 handlers) [GIN-debug] POST /posts --> main.Store (3 handlers) [GIN-debug] PATCH /posts/:id --> main.Update (3 handlers) [GIN-debug] DELETE /posts/:id --> main.Delete (3 handlers) [GIN-debug] Listening and serving HTTP on :9090

it should build and then run that build executable, but unfortunately it does not happen.

I have make all mentioned changes to Run() funtion and all other stuff, but still the same outcome.

Please help!

Thanks in advance!

zzeynal avatar Jun 12 '20 15:06 zzeynal

@zzeynal Your question isn't watcher related, so I would post this question in a more appropriate place. I would however ensure that go build and go run works for your app, otherwise watcher won't be able to run it either. good luck

tzusman avatar Jun 12 '20 16:06 tzusman

@zzeynal Your question isn't watcher related, so I would post this question in a more appropriate place. I would however ensure that go build and go run works for your app, otherwise watcher won't be able to run it either. good luck

@tzusman yes, sure while running go build and go run commands my app works.

Much appreciate your support.

zzeynal avatar Jun 12 '20 16:06 zzeynal

ok i've found the issue and got a fix for it. it's not done yet but the problem is the change to zsh from bash on MacOS Catalina. I will try to get it done tomorrow after work.

If you're on Catalina and just want to get it working, change runCommand() in common.go:

func runCommand(name string, args ...string) (*exec.Cmd, error) {
	var cmd *exec.Cmd

	if len(args) == 0 {
		cmd = exec.CommandContext(context.Background(), "/bin/zsh", "-c", name)
	} else {
		cmd = exec.Command(name, args...)
	}

	stderr, err := cmd.StderrPipe()
	if err != nil {
		return cmd, err
	}

	stdout, err := cmd.StdoutPipe()
	if err != nil {
		return cmd, err
	}

	if err := cmd.Start(); err != nil {
		return cmd, err
	}

	go io.Copy(os.Stdout, stdout)
	go io.Copy(os.Stderr, stderr)

	return cmd, nil
}

and then change Run() in run.go:

func (r *Runner) Run(p *Params) {
	for fileName := range r.start {

		color.Green("Running %s...\n", p.Get("run"))

		cmd, err := runCommand(fileName, p.Package...)
		if err != nil {
			log.Printf("Could not run the go binary: %s \n", err)
			r.kill(cmd)

			continue
		}

		r.cmd = cmd

		go func(cmd *exec.Cmd, fileName string) {
			if err := cmd.Wait(); err != nil {
				log.Printf("process interrupted: %s \n", err)
				r.kill(cmd)
			}

			removeFile(fileName)
		}(r.cmd, fileName)
	}
}

after changing Run() func in run.go file I got such a problem:

exported method Runner.Run should have comment or be unexported go-lint

Please advice.

zzeynal avatar Jun 13 '20 11:06 zzeynal

Guys solved my issue! Everything is done great, based upon your advice.

Thanks!

zzeynal avatar Jun 14 '20 12:06 zzeynal

I have the same issue with Mac OS Catalina. How do I build the watcher after I change the code?

❯ watcher -c config.dev.yaml 2020/10/16 10:35:48 build started Building .... 2020/10/16 10:35:55 build completed Running ... 2020/10/16 10:35:55 process interrupted: signal: killed

yalexx avatar Oct 16 '20 07:10 yalexx

any progress on this issue?

fajardm avatar Aug 23 '21 12:08 fajardm