ronantakizawa/codereview-bench huggingface dataset:
Repository: ollama/ollama
File: cmd/cmd.go (Go)

Code before:
		if !strings.Contains(err.Error(), "connection refused") {
			return err
		}
		if runtime.GOOS == "darwin" {
			if err := startMacApp(cmd.Context(), client); err != nil {
				return fmt.Errorf("could not connect to ollama app, is it running?")
			}
		} else {
			return fmt.Errorf("could not connect to ollama server, run 'ollama serve' to start it")
		}
	}
	return nil
}

func versionHandler(cmd *cobra.Command, _ []string) {
	client, err := api.ClientFromEnvironment()
	if err != nil {
		return
	}

	serverVersion, err := client.Version(cmd.Context())
	if err != nil {
		fmt.Println("Warning: Your server is not accessible")
	}

	if serverVersion != "" {
		fmt.Printf("Your ollama version %s\n", serverVersion)
	}

	if serverVersion != version.Version {
		fmt.Printf("Warning: Your client version is %s\n", version.Version)
	}
}

func NewCLI() *cobra.Command {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	cobra.EnableCommandSorting = false

	rootCmd := &cobra.Command{
		Use:           "ollama",
		Short:         "Large language model runner",
		SilenceUsage:  true,
		SilenceErrors: true,
		CompletionOptions: cobra.CompletionOptions{
			DisableDefaultCmd: true,
		},
		Run: func(cmd *cobra.Command, args []string) {
			if version, _ := cmd.Flags().GetBool("version"); version {
				versionHandler(cmd, args)
				return
			}

Review comment (suggestion):
```suggestion
		fmt.Println("Warning: Could not connect to a running instance of Ollama")
```
Just a suggestion where a lot people using Ollama aren't thinking of it this client/server context due to how it runs on desktop.

Code after:
		return err
	}
	if err := client.Heartbeat(cmd.Context()); err != nil {
		if !strings.Contains(err.Error(), "connection refused") {
			return err
		}
		if runtime.GOOS == "darwin" {
			if err := startMacApp(cmd.Context(), client); err != nil {
				return fmt.Errorf("could not connect to ollama app, is it running?")
			}
		} else {
			return fmt.Errorf("could not connect to ollama server, run 'ollama serve' to start it")
		}
	}
	return nil
}

func versionHandler(cmd *cobra.Command, _ []string) {
	client, err := api.ClientFromEnvironment()
	if err != nil {
		return
	}

	serverVersion, err := client.Version(cmd.Context())
	if err != nil {
		fmt.Println("Warning: could not connect to a running Ollama instance")
	}

	if serverVersion != "" {
		fmt.Printf("ollama version is %s\n", serverVersion)
	}

	if serverVersion != version.Version {
		fmt.Printf("Warning: client version is %s\n", version.Version)
	}
}

func NewCLI() *cobra.Command {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	cobra.EnableCommandSorting = false

	rootCmd := &cobra.Command{
		Use:           "ollama",
		Short:         "Large language model runner",
		SilenceUsage:  true,
		SilenceErrors: true,
		CompletionOptions: cobra.CompletionOptions{
			DisableDefaultCmd: true,
		},
		Run: func(cmd *cobra.Command, args []string) {
			if version, _ := cmd.Flags().GetBool("version"); version {
Repository: ollama/ollama
File: cmd/cmd.go (Go)

Code before:
			if err := startMacApp(cmd.Context(), client); err != nil {
				return fmt.Errorf("could not connect to ollama app, is it running?")
			}
		} else {
			return fmt.Errorf("could not connect to ollama server, run 'ollama serve' to start it")
		}
	}
	return nil
}

func versionHandler(cmd *cobra.Command, _ []string) {
	client, err := api.ClientFromEnvironment()
	if err != nil {
		return
	}

	serverVersion, err := client.Version(cmd.Context())
	if err != nil {
		fmt.Println("Warning: Your server is not accessible")
	}

	if serverVersion != "" {
		fmt.Printf("Your ollama version %s\n", serverVersion)
	}

	if serverVersion != version.Version {
		fmt.Printf("Warning: Your client version is %s\n", version.Version)
	}
}

func NewCLI() *cobra.Command {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	cobra.EnableCommandSorting = false

	rootCmd := &cobra.Command{
		Use:           "ollama",
		Short:         "Large language model runner",
		SilenceUsage:  true,
		SilenceErrors: true,
		CompletionOptions: cobra.CompletionOptions{
			DisableDefaultCmd: true,
		},
		Run: func(cmd *cobra.Command, args []string) {
			if version, _ := cmd.Flags().GetBool("version"); version {
				versionHandler(cmd, args)
				return
			}

			cmd.Print(cmd.UsageString())
		},
	}

Review comment (suggestion):

```suggestion
		fmt.Printf("%s\n", serverVersion)
```

Code after:
			return err
		}
		if runtime.GOOS == "darwin" {
			if err := startMacApp(cmd.Context(), client); err != nil {
				return fmt.Errorf("could not connect to ollama app, is it running?")
			}
		} else {
			return fmt.Errorf("could not connect to ollama server, run 'ollama serve' to start it")
		}
	}
	return nil
}

func versionHandler(cmd *cobra.Command, _ []string) {
	client, err := api.ClientFromEnvironment()
	if err != nil {
		return
	}

	serverVersion, err := client.Version(cmd.Context())
	if err != nil {
		fmt.Println("Warning: could not connect to a running Ollama instance")
	}

	if serverVersion != "" {
		fmt.Printf("ollama version is %s\n", serverVersion)
	}

	if serverVersion != version.Version {
		fmt.Printf("Warning: client version is %s\n", version.Version)
	}
}

func NewCLI() *cobra.Command {
	log.SetFlags(log.LstdFlags | log.Lshortfile)
	cobra.EnableCommandSorting = false

	rootCmd := &cobra.Command{
		Use:           "ollama",
		Short:         "Large language model runner",
		SilenceUsage:  true,
		SilenceErrors: true,
		CompletionOptions: cobra.CompletionOptions{
			DisableDefaultCmd: true,
		},
		Run: func(cmd *cobra.Command, args []string) {
			if version, _ := cmd.Flags().GetBool("version"); version {
				versionHandler(cmd, args)
				return
			}
Repository: ollama/ollama
File: app/src/index.ts (TypeScript)

Code before:

  proc.stderr.on('data', data => {
    logger.error(data.toString().trim())
  })

  proc.on('exit', restart)
}

function restart() {
  setTimeout(server, 1000)
}

app.on('before-quit', () => {
  if (proc) {
    proc.off('exit', restart)
    proc.kill('SIGINT') // send SIGINT signal to the server, which also stops any loaded llms
  }
})

interface ReleaseData {
  url: string
}

var currentRelesaseURL = ''

async function checkNewRelease(): Promise<boolean> {
  try {
    const response = await fetch('https://ollama.ai/api/update')

    if (!response.ok) {
      logger.error(`update server responded with ${response.status}`)
      return false
    }

    const data: ReleaseData = await response.json()
    const fetchedURL = data.url

    const newRelease = currentRelesaseURL === '' || currentRelesaseURL !== fetchedURL
    currentRelesaseURL = fetchedURL

    return newRelease
  } catch (error) {
    logger.error(`update check failed - ${error}`)
    return false
  }
}

function checkUpdate() {
  checkNewRelease().then(check => {
    if (check) {
      logger.info('update available')

Review comment (suggestion):
```suggestion
async function checkNewRelease() {
```

Code after:

  proc.stderr.on('data', data => {
    logger.error(data.toString().trim())
  })

  proc.on('exit', restart)
}

function restart() {
  setTimeout(server, 1000)
}

app.on('before-quit', () => {
  if (proc) {
    proc.off('exit', restart)
    proc.kill('SIGINT') // send SIGINT signal to the server, which also stops any loaded llms
  }
})

let currentReleaseURL = ''

async function isNewReleaseAvailable() {
  try {
    const response = await fetch('https://ollama.ai/api/update')

    if (response.status === 204) {
      return false
    }

    const data = await response.json()

    if (currentReleaseURL === data.url) {
      return false
    }

    currentReleaseURL = data.url
    return true
  } catch (error) {
    logger.error(`update check failed - ${error}`)
    return false
  }
}

async function checkUpdate() {
  const available = await isNewReleaseAvailable()
  if (available) {
    logger.info('checking for update')
    autoUpdater.checkForUpdates()
  }
}
Repository: ollama/ollama
File: app/src/index.ts (TypeScript)

Code before:
var currentRelesaseURL = ''

async function checkNewRelease(): Promise<boolean> {
  try {
    const response = await fetch('https://ollama.ai/api/update')

    if (!response.ok) {
      logger.error(`update server responded with ${response.status}`)
      return false
    }

    const data: ReleaseData = await response.json()
    const fetchedURL = data.url

    const newRelease = currentRelesaseURL === '' || currentRelesaseURL !== fetchedURL
    currentRelesaseURL = fetchedURL

    return newRelease
  } catch (error) {
    logger.error(`update check failed - ${error}`)
    return false
  }
}

function checkUpdate() {
  checkNewRelease().then(check => {
    if (check) {
      logger.info('update available')
      autoUpdater.checkForUpdates()
    }
  })
}

function init() {
  if (app.isPackaged) {
    checkUpdate()
    setInterval(() => {
      checkUpdate()
    }, 60 * 60 * 1000)
  }

  updateTray()

  if (process.platform === 'darwin') {
    if (app.isPackaged) {
      if (!app.isInApplicationsFolder()) {
        const chosen = dialog.showMessageBoxSync({
          type: 'question',
          buttons: ['Move to Applications', 'Do Not Move'],
          message: 'Ollama works best when run from the Applications directory.',
          defaultId: 0,

Review comment (suggestion):
```suggestion
const check = await checkNewRelease()
if (check) {
  logger.info('update available')
  autoUpdater.checkForUpdates()
}
```

Code after:
    const response = await fetch('https://ollama.ai/api/update')

    if (response.status === 204) {
      return false
    }

    const data = await response.json()

    if (currentReleaseURL === data.url) {
      return false
    }

    currentReleaseURL = data.url
    return true
  } catch (error) {
    logger.error(`update check failed - ${error}`)
    return false
  }
}

async function checkUpdate() {
  const available = await isNewReleaseAvailable()
  if (available) {
    logger.info('checking for update')
    autoUpdater.checkForUpdates()
  }
}

function init() {
  if (app.isPackaged) {
    checkUpdate()
    setInterval(() => {
      checkUpdate()
    }, 60 * 60 * 1000)
  }

  updateTray()

  if (process.platform === 'darwin') {
    if (app.isPackaged) {
      if (!app.isInApplicationsFolder()) {
        const chosen = dialog.showMessageBoxSync({
          type: 'question',
          buttons: ['Move to Applications', 'Do Not Move'],
          message: 'Ollama works best when run from the Applications directory.',
          defaultId: 0,
          cancelId: 1,
        })

        if (chosen === 0) {
          try {
Repository: ollama/ollama
File: app/src/index.ts (TypeScript)

Code before:
  setTimeout(server, 1000)
}

app.on('before-quit', () => {
  if (proc) {
    proc.off('exit', restart)
    proc.kill('SIGINT') // send SIGINT signal to the server, which also stops any loaded llms
  }
})

interface ReleaseData {
  url: string
}

var currentRelesaseURL = ''

async function checkNewRelease(): Promise<boolean> {
  try {
    const response = await fetch('https://ollama.ai/api/update')

    if (!response.ok) {
      logger.error(`update server responded with ${response.status}`)
      return false
    }

    const data: ReleaseData = await response.json()
    const fetchedURL = data.url

    const newRelease = currentRelesaseURL === '' || currentRelesaseURL !== fetchedURL
    currentRelesaseURL = fetchedURL

    return newRelease
  } catch (error) {
    logger.error(`update check failed - ${error}`)
    return false
  }
}

function checkUpdate() {
  checkNewRelease().then(check => {
    if (check) {
      logger.info('update available')
      autoUpdater.checkForUpdates()
    }
  })
}

function init() {
  if (app.isPackaged) {
    checkUpdate()
    setInterval(() => {

Review comment (suggestion):
```suggestion
    const data = await response.json()
```

Code after:
  setTimeout(server, 1000)
}

app.on('before-quit', () => {
  if (proc) {
    proc.off('exit', restart)
    proc.kill('SIGINT') // send SIGINT signal to the server, which also stops any loaded llms
  }
})

let currentReleaseURL = ''

async function isNewReleaseAvailable() {
  try {
    const response = await fetch('https://ollama.ai/api/update')

    if (response.status === 204) {
      return false
    }

    const data = await response.json()

    if (currentReleaseURL === data.url) {
      return false
    }

    currentReleaseURL = data.url
    return true
  } catch (error) {
    logger.error(`update check failed - ${error}`)
    return false
  }
}

async function checkUpdate() {
  const available = await isNewReleaseAvailable()
  if (available) {
    logger.info('checking for update')
    autoUpdater.checkForUpdates()
  }
}

function init() {
  if (app.isPackaged) {
    checkUpdate()
    setInterval(() => {
      checkUpdate()
    }, 60 * 60 * 1000)
  }

  updateTray()
Repository: ollama/ollama
File: app/src/index.ts (TypeScript)

Code before:

var currentRelesaseURL = ''

async function checkNewRelease(): Promise<boolean> {
  try {
    const response = await fetch('https://ollama.ai/api/update')

    if (!response.ok) {
      logger.error(`update server responded with ${response.status}`)
      return false
    }

    const data: ReleaseData = await response.json()
    const fetchedURL = data.url

    const newRelease = currentRelesaseURL === '' || currentRelesaseURL !== fetchedURL
    currentRelesaseURL = fetchedURL

    return newRelease
  } catch (error) {
    logger.error(`update check failed - ${error}`)
    return false
  }
}

function checkUpdate() {
  checkNewRelease().then(check => {
    if (check) {
      logger.info('update available')
      autoUpdater.checkForUpdates()
    }
  })
}

function init() {
  if (app.isPackaged) {
    checkUpdate()
    setInterval(() => {
      checkUpdate()
    }, 60 * 60 * 1000)
  }

  updateTray()

  if (process.platform === 'darwin') {
    if (app.isPackaged) {
      if (!app.isInApplicationsFolder()) {
        const chosen = dialog.showMessageBoxSync({
          type: 'question',
          buttons: ['Move to Applications', 'Do Not Move'],
          message: 'Ollama works best when run from the Applications directory.',

Review comment (suggestion):
```suggestion
async function checkUpdate() {
```

Code after:
  try {
    const response = await fetch('https://ollama.ai/api/update')

    if (response.status === 204) {
      return false
    }

    const data = await response.json()

    if (currentReleaseURL === data.url) {
      return false
    }

    currentReleaseURL = data.url
    return true
  } catch (error) {
    logger.error(`update check failed - ${error}`)
    return false
  }
}

async function checkUpdate() {
  const available = await isNewReleaseAvailable()
  if (available) {
    logger.info('checking for update')
    autoUpdater.checkForUpdates()
  }
}

function init() {
  if (app.isPackaged) {
    checkUpdate()
    setInterval(() => {
      checkUpdate()
    }, 60 * 60 * 1000)
  }

  updateTray()

  if (process.platform === 'darwin') {
    if (app.isPackaged) {
      if (!app.isInApplicationsFolder()) {
        const chosen = dialog.showMessageBoxSync({
          type: 'question',
          buttons: ['Move to Applications', 'Do Not Move'],
          message: 'Ollama works best when run from the Applications directory.',
          defaultId: 0,
          cancelId: 1,
        })

        if (chosen === 0) {
Repository: ollama/ollama
File: app/src/index.ts (TypeScript)

Code before:
  })

  proc.on('exit', restart)
}

function restart() {
  setTimeout(server, 1000)
}

app.on('before-quit', () => {
  if (proc) {
    proc.off('exit', restart)
    proc.kill('SIGINT') // send SIGINT signal to the server, which also stops any loaded llms
  }
})

let currentReleaseURL = ''

async function checkNewRelease() {
  try {
    const response = await fetch('https://ollama.ai/api/update')

    if (!response.ok) {
      logger.error(`update server responded with ${response.status}`)
      return false
    }

    const data = await response.json()
    const fetchedURL = data.url

    const newRelease = currentReleaseURL === '' || currentReleaseURL !== fetchedURL
    currentReleaseURL = fetchedURL

    return newRelease
  } catch (error) {
    logger.error(`update check failed - ${error}`)
    return false
  }
}

async function checkUpdate() {
  const check = await checkNewRelease()
  if (check) {
    logger.info('update available')
    autoUpdater.checkForUpdates()
  }
}

function init() {
  if (app.isPackaged) {
    checkUpdate()

Review comment (suggestion):
```suggestion
if (response.status === 204) {
  return false
}
```

Code after:
  })

  proc.on('exit', restart)
}

function restart() {
  setTimeout(server, 1000)
}

app.on('before-quit', () => {
  if (proc) {
    proc.off('exit', restart)
    proc.kill('SIGINT') // send SIGINT signal to the server, which also stops any loaded llms
  }
})

let currentReleaseURL = ''

async function isNewReleaseAvailable() {
  try {
    const response = await fetch('https://ollama.ai/api/update')

    if (response.status === 204) {
      return false
    }

    const data = await response.json()

    if (currentReleaseURL === data.url) {
      return false
    }

    currentReleaseURL = data.url
    return true
  } catch (error) {
    logger.error(`update check failed - ${error}`)
    return false
  }
}

async function checkUpdate() {
  const available = await isNewReleaseAvailable()
  if (available) {
    logger.info('checking for update')
    autoUpdater.checkForUpdates()
  }
}

function init() {
  if (app.isPackaged) {
    checkUpdate()
Repository: ollama/ollama
File: app/src/index.ts (TypeScript)

Code before:

app.on('before-quit', () => {
  if (proc) {
    proc.off('exit', restart)
    proc.kill('SIGINT') // send SIGINT signal to the server, which also stops any loaded llms
  }
})

let currentReleaseURL = ''

async function checkNewRelease() {
  try {
    const response = await fetch('https://ollama.ai/api/update')

    if (!response.ok) {
      logger.error(`update server responded with ${response.status}`)
      return false
    }

    const data = await response.json()
    const fetchedURL = data.url

    const newRelease = currentReleaseURL === '' || currentReleaseURL !== fetchedURL
    currentReleaseURL = fetchedURL

    return newRelease
  } catch (error) {
    logger.error(`update check failed - ${error}`)
    return false
  }
}

async function checkUpdate() {
  const check = await checkNewRelease()
  if (check) {
    logger.info('update available')
    autoUpdater.checkForUpdates()
  }
}

function init() {
  if (app.isPackaged) {
    checkUpdate()
    setInterval(() => {
      checkUpdate()
    }, 60 * 60 * 1000)
  }

  updateTray()

  if (process.platform === 'darwin') {

Review comment (suggestion):
```suggestion
    if (currentReleaseURL === data.url) {
      return false
    }

    currentReleaseURL = data.url
    return true
```

Code after:

app.on('before-quit', () => {
  if (proc) {
    proc.off('exit', restart)
    proc.kill('SIGINT') // send SIGINT signal to the server, which also stops any loaded llms
  }
})

let currentReleaseURL = ''

async function isNewReleaseAvailable() {
  try {
    const response = await fetch('https://ollama.ai/api/update')

    if (response.status === 204) {
      return false
    }

    const data = await response.json()

    if (currentReleaseURL === data.url) {
      return false
    }

    currentReleaseURL = data.url
    return true
  } catch (error) {
    logger.error(`update check failed - ${error}`)
    return false
  }
}

async function checkUpdate() {
  const available = await isNewReleaseAvailable()
  if (available) {
    logger.info('checking for update')
    autoUpdater.checkForUpdates()
  }
}

function init() {
  if (app.isPackaged) {
    checkUpdate()
    setInterval(() => {
      checkUpdate()
    }, 60 * 60 * 1000)
  }

  updateTray()

  if (process.platform === 'darwin') {
Repository: ollama/ollama
File: app/src/index.ts (TypeScript)

Code before:
let currentReleaseURL = ''

async function checkNewRelease() {
  try {
    const response = await fetch('https://ollama.ai/api/update')

    if (!response.ok) {
      logger.error(`update server responded with ${response.status}`)
      return false
    }

    const data = await response.json()
    const fetchedURL = data.url

    const newRelease = currentReleaseURL === '' || currentReleaseURL !== fetchedURL
    currentReleaseURL = fetchedURL

    return newRelease
  } catch (error) {
    logger.error(`update check failed - ${error}`)
    return false
  }
}

async function checkUpdate() {
  const check = await checkNewRelease()
  if (check) {
    logger.info('update available')
    autoUpdater.checkForUpdates()
  }
}

function init() {
  if (app.isPackaged) {
    checkUpdate()
    setInterval(() => {
      checkUpdate()
    }, 60 * 60 * 1000)
  }

  updateTray()

  if (process.platform === 'darwin') {
    if (app.isPackaged) {
      if (!app.isInApplicationsFolder()) {
        const chosen = dialog.showMessageBoxSync({
          type: 'question',
          buttons: ['Move to Applications', 'Do Not Move'],
          message: 'Ollama works best when run from the Applications directory.',
          defaultId: 0,
          cancelId: 1,

Review comment (suggestion):
```suggestion
  const available = await isNewReleaseAvailable()
```

Code after:
let currentReleaseURL = ''

async function isNewReleaseAvailable() {
  try {
    const response = await fetch('https://ollama.ai/api/update')

    if (response.status === 204) {
      return false
    }

    const data = await response.json()

    if (currentReleaseURL === data.url) {
      return false
    }

    currentReleaseURL = data.url
    return true
  } catch (error) {
    logger.error(`update check failed - ${error}`)
    return false
  }
}

async function checkUpdate() {
  const available = await isNewReleaseAvailable()
  if (available) {
    logger.info('checking for update')
    autoUpdater.checkForUpdates()
  }
}

function init() {
  if (app.isPackaged) {
    checkUpdate()
    setInterval(() => {
      checkUpdate()
    }, 60 * 60 * 1000)
  }

  updateTray()

  if (process.platform === 'darwin') {
    if (app.isPackaged) {
      if (!app.isInApplicationsFolder()) {
        const chosen = dialog.showMessageBoxSync({
          type: 'question',
          buttons: ['Move to Applications', 'Do Not Move'],
          message: 'Ollama works best when run from the Applications directory.',
          defaultId: 0,
          cancelId: 1,